@arcanejs/toolkit-frontend 0.6.1 → 0.7.0
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/README.md +1 -1
- package/dist/components/index.d.mts +2 -1
- package/dist/components/index.d.ts +2 -1
- package/dist/components/index.js +23 -13
- package/dist/components/index.mjs +22 -12
- package/dist/types.d.mts +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/util/index.d.mts +1 -1
- package/dist/util/index.d.ts +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ and can only be applied to objects that match the type
|
|
|
13
13
|
of the objects being compared.
|
|
14
14
|
|
|
15
15
|
This package is part of the
|
|
16
|
-
[`arcanejs` project](https://github.com/
|
|
16
|
+
[`arcanejs` project](https://github.com/ArcaneWizards/arcanejs#arcanejs),
|
|
17
17
|
and is used to maintain a copy of a JSON tree in downstream clients in real-time
|
|
18
18
|
via websockets.
|
|
19
19
|
|
|
@@ -12,7 +12,8 @@ interface Props$8 {
|
|
|
12
12
|
declare const StyledButton: FC<Props$8>;
|
|
13
13
|
|
|
14
14
|
type StageContextData = {
|
|
15
|
-
sendMessage: (<M extends proto$1.
|
|
15
|
+
sendMessage: (<M extends proto$1.AnyClientComponentMessage>(msg: M) => void) | null;
|
|
16
|
+
call: (<Namespace extends string, P, Action extends string & keyof P>(msg: proto$1.CallForPair<Namespace, P, Action>) => Promise<proto$1.ReturnForPair<P, Action>>) | null;
|
|
16
17
|
renderComponent: (info: proto$1.AnyComponentProto) => JSX.Element;
|
|
17
18
|
connectionUuid: string;
|
|
18
19
|
};
|
|
@@ -12,7 +12,8 @@ interface Props$8 {
|
|
|
12
12
|
declare const StyledButton: FC<Props$8>;
|
|
13
13
|
|
|
14
14
|
type StageContextData = {
|
|
15
|
-
sendMessage: (<M extends proto$1.
|
|
15
|
+
sendMessage: (<M extends proto$1.AnyClientComponentMessage>(msg: M) => void) | null;
|
|
16
|
+
call: (<Namespace extends string, P, Action extends string & keyof P>(msg: proto$1.CallForPair<Namespace, P, Action>) => Promise<proto$1.ReturnForPair<P, Action>>) | null;
|
|
16
17
|
renderComponent: (info: proto$1.AnyComponentProto) => JSX.Element;
|
|
17
18
|
connectionUuid: string;
|
|
18
19
|
};
|
package/dist/components/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
@@ -38,6 +38,7 @@ var StageContext = _react.createContext.call(void 0,
|
|
|
38
38
|
// src/components/button.tsx
|
|
39
39
|
var _jsxruntime = require('react/jsx-runtime');
|
|
40
40
|
var TOUCH_INDICATOR_CLASS = "touch-indicator";
|
|
41
|
+
var LOADING_CLASS = "loading";
|
|
41
42
|
var TOUCHING_CLASS = "touching";
|
|
42
43
|
var ERROR_CLASS = "error";
|
|
43
44
|
var ButtonContents = _styledcomponents.styled.div`
|
|
@@ -54,22 +55,31 @@ var ButtonLabel = _styledcomponents.styled.span`
|
|
|
54
55
|
padding: 0 4px;
|
|
55
56
|
`;
|
|
56
57
|
var Button = (props) => {
|
|
57
|
-
const {
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
58
|
+
const { call } = _react2.default.useContext(StageContext);
|
|
59
|
+
const [localState, setLocalState] = _react2.default.useState(null);
|
|
60
|
+
const state = _nullishCoalesce(localState, () => ( props.info.state));
|
|
61
|
+
const { touching, handlers } = _chunk7VTNOX5Ojs.usePressable.call(void 0, async () => {
|
|
62
|
+
try {
|
|
63
|
+
if (!call) return;
|
|
64
|
+
setLocalState({ state: "loading" });
|
|
65
|
+
await _optionalChain([call, 'optionalCall', _ => _({
|
|
66
|
+
type: "component-call",
|
|
67
|
+
namespace: "core",
|
|
68
|
+
componentKey: props.info.key,
|
|
69
|
+
action: "press"
|
|
70
|
+
})]);
|
|
71
|
+
setLocalState(null);
|
|
72
|
+
} catch (e) {
|
|
73
|
+
setLocalState({ state: "error", error: `${e}` });
|
|
74
|
+
}
|
|
75
|
+
});
|
|
67
76
|
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
68
77
|
"div",
|
|
69
78
|
{
|
|
70
79
|
className: _chunk7VTNOX5Ojs.calculateClass.call(void 0,
|
|
71
80
|
props.className,
|
|
72
|
-
touching || state.state === "pressed"
|
|
81
|
+
(touching || state.state === "pressed") && TOUCHING_CLASS,
|
|
82
|
+
state.state === "loading" && LOADING_CLASS,
|
|
73
83
|
state.state === "error" && ERROR_CLASS
|
|
74
84
|
),
|
|
75
85
|
...handlers,
|
|
@@ -100,7 +110,7 @@ var StyledButton = _styledcomponents.styled.call(void 0, Button)`
|
|
|
100
110
|
border-color: ${(p) => p.theme.colorRed};
|
|
101
111
|
}
|
|
102
112
|
|
|
103
|
-
&.${TOUCHING_CLASS} {
|
|
113
|
+
&.${TOUCHING_CLASS}, &.${LOADING_CLASS} {
|
|
104
114
|
${_chunkWVMAJYGIjs.buttonStateNormalActive}
|
|
105
115
|
|
|
106
116
|
.${TOUCH_INDICATOR_CLASS} {
|
|
@@ -38,6 +38,7 @@ var StageContext = createContext(
|
|
|
38
38
|
// src/components/button.tsx
|
|
39
39
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
40
40
|
var TOUCH_INDICATOR_CLASS = "touch-indicator";
|
|
41
|
+
var LOADING_CLASS = "loading";
|
|
41
42
|
var TOUCHING_CLASS = "touching";
|
|
42
43
|
var ERROR_CLASS = "error";
|
|
43
44
|
var ButtonContents = styled.div`
|
|
@@ -54,22 +55,31 @@ var ButtonLabel = styled.span`
|
|
|
54
55
|
padding: 0 4px;
|
|
55
56
|
`;
|
|
56
57
|
var Button = (props) => {
|
|
57
|
-
const {
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
58
|
+
const { call } = React.useContext(StageContext);
|
|
59
|
+
const [localState, setLocalState] = React.useState(null);
|
|
60
|
+
const state = localState ?? props.info.state;
|
|
61
|
+
const { touching, handlers } = usePressable(async () => {
|
|
62
|
+
try {
|
|
63
|
+
if (!call) return;
|
|
64
|
+
setLocalState({ state: "loading" });
|
|
65
|
+
await call?.({
|
|
66
|
+
type: "component-call",
|
|
67
|
+
namespace: "core",
|
|
68
|
+
componentKey: props.info.key,
|
|
69
|
+
action: "press"
|
|
70
|
+
});
|
|
71
|
+
setLocalState(null);
|
|
72
|
+
} catch (e) {
|
|
73
|
+
setLocalState({ state: "error", error: `${e}` });
|
|
74
|
+
}
|
|
75
|
+
});
|
|
67
76
|
return /* @__PURE__ */ jsxs(
|
|
68
77
|
"div",
|
|
69
78
|
{
|
|
70
79
|
className: calculateClass(
|
|
71
80
|
props.className,
|
|
72
|
-
touching || state.state === "pressed"
|
|
81
|
+
(touching || state.state === "pressed") && TOUCHING_CLASS,
|
|
82
|
+
state.state === "loading" && LOADING_CLASS,
|
|
73
83
|
state.state === "error" && ERROR_CLASS
|
|
74
84
|
),
|
|
75
85
|
...handlers,
|
|
@@ -100,7 +110,7 @@ var StyledButton = styled(Button)`
|
|
|
100
110
|
border-color: ${(p) => p.theme.colorRed};
|
|
101
111
|
}
|
|
102
112
|
|
|
103
|
-
&.${TOUCHING_CLASS} {
|
|
113
|
+
&.${TOUCHING_CLASS}, &.${LOADING_CLASS} {
|
|
104
114
|
${buttonStateNormalActive}
|
|
105
115
|
|
|
106
116
|
.${TOUCH_INDICATOR_CLASS} {
|
package/dist/types.d.mts
CHANGED
|
@@ -2,7 +2,7 @@ import { BaseComponentProto } from '@arcanejs/protocol';
|
|
|
2
2
|
|
|
3
3
|
type FrontendComponentRenderer = {
|
|
4
4
|
namespace: string;
|
|
5
|
-
render: (component: BaseComponentProto<string>) => JSX.Element;
|
|
5
|
+
render: (component: BaseComponentProto<string, string>) => JSX.Element;
|
|
6
6
|
};
|
|
7
7
|
type FrontendComponentRenderers = FrontendComponentRenderer[];
|
|
8
8
|
|
package/dist/types.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { BaseComponentProto } from '@arcanejs/protocol';
|
|
|
2
2
|
|
|
3
3
|
type FrontendComponentRenderer = {
|
|
4
4
|
namespace: string;
|
|
5
|
-
render: (component: BaseComponentProto<string>) => JSX.Element;
|
|
5
|
+
render: (component: BaseComponentProto<string, string>) => JSX.Element;
|
|
6
6
|
};
|
|
7
7
|
type FrontendComponentRenderers = FrontendComponentRenderer[];
|
|
8
8
|
|
package/dist/util/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
declare function switchToMouseMode(ev: MouseEvent): void;
|
|
2
2
|
declare function switchToTouchMode(): void;
|
|
3
3
|
declare function initialiseListeners(): void;
|
|
4
|
-
declare const usePressable: (click: () =>
|
|
4
|
+
declare const usePressable: (click: () => unknown) => {
|
|
5
5
|
touching: boolean;
|
|
6
6
|
handlers: {
|
|
7
7
|
onClick: React.MouseEventHandler<unknown>;
|
package/dist/util/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
declare function switchToMouseMode(ev: MouseEvent): void;
|
|
2
2
|
declare function switchToTouchMode(): void;
|
|
3
3
|
declare function initialiseListeners(): void;
|
|
4
|
-
declare const usePressable: (click: () =>
|
|
4
|
+
declare const usePressable: (click: () => unknown) => {
|
|
5
5
|
touching: boolean;
|
|
6
6
|
handlers: {
|
|
7
7
|
onClick: React.MouseEventHandler<unknown>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcanejs/toolkit-frontend",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Library of the frontend react components used to render the @arcanejs Toolkit",
|
|
6
6
|
"keywords": [],
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
},
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
14
|
-
"url": "https://github.com/
|
|
14
|
+
"url": "https://github.com/ArcaneWizards/arcanejs.git"
|
|
15
15
|
},
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"react": "^18",
|
|
63
63
|
"react-dom": "18.3.1",
|
|
64
64
|
"styled-components": "^6.1.13",
|
|
65
|
-
"@arcanejs/protocol": "^0.
|
|
65
|
+
"@arcanejs/protocol": "^0.7.0"
|
|
66
66
|
},
|
|
67
67
|
"files": [
|
|
68
68
|
"dist"
|