@arcanejs/toolkit-frontend 0.6.1 → 0.8.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 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/arcanejs/arcanejs#arcanejs),
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
 
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  usePreferredColorScheme
3
- } from "./chunk-E7JSREGM.mjs";
3
+ } from "./chunk-PTANIWKR.mjs";
4
4
 
5
5
  // src/styling.tsx
6
6
  import {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  __export,
3
3
  calculateClass
4
- } from "./chunk-E7JSREGM.mjs";
4
+ } from "./chunk-PTANIWKR.mjs";
5
5
 
6
6
  // src/components/core/index.ts
7
7
  var core_exports = {};
@@ -73,7 +73,57 @@ function trackTouch(touch, move, end) {
73
73
 
74
74
  // src/util/index.ts
75
75
  var calculateClass = (...args) => args.filter((a) => !!a).join(" ");
76
+ var COLOR_SCHEME_SETTINGS = "arcane-color-scheme-preference";
77
+ var VALID_COLOR_SCHEME_PREFS = ["auto", "dark", "light"];
78
+ var isValidColorSchemePreference = (value) => {
79
+ return VALID_COLOR_SCHEME_PREFS.includes(value);
80
+ };
81
+ var useColorSchemePreferences = () => {
82
+ if (typeof window === "undefined") {
83
+ return {
84
+ colorSchemePreference: "auto",
85
+ setColorSchemePreference: () => {
86
+ }
87
+ };
88
+ }
89
+ const [preference, setPreference] = useState2(
90
+ window.localStorage.getItem(
91
+ COLOR_SCHEME_SETTINGS
92
+ ) || "auto"
93
+ );
94
+ const setColorSchemePreference = (newPreference) => {
95
+ if (!isValidColorSchemePreference(newPreference)) {
96
+ throw new Error(`Invalid color scheme preference: ${newPreference}`);
97
+ }
98
+ window.localStorage.setItem(COLOR_SCHEME_SETTINGS, newPreference);
99
+ window.dispatchEvent(
100
+ new StorageEvent("storage", {
101
+ key: COLOR_SCHEME_SETTINGS,
102
+ newValue: newPreference
103
+ })
104
+ );
105
+ };
106
+ useEffect(() => {
107
+ const onStorageChange = (event) => {
108
+ if (event.key === COLOR_SCHEME_SETTINGS) {
109
+ const newValue = event.newValue;
110
+ if (isValidColorSchemePreference(newValue)) {
111
+ setPreference(newValue);
112
+ }
113
+ }
114
+ };
115
+ window.addEventListener("storage", onStorageChange);
116
+ return () => {
117
+ window.removeEventListener("storage", onStorageChange);
118
+ };
119
+ }, []);
120
+ return {
121
+ colorSchemePreference: isValidColorSchemePreference(preference) ? preference : "auto",
122
+ setColorSchemePreference
123
+ };
124
+ };
76
125
  var usePreferredColorScheme = () => {
126
+ const { colorSchemePreference } = useColorSchemePreferences();
77
127
  const [theme, setTheme] = useState2("light");
78
128
  useEffect(() => {
79
129
  if (typeof window !== "undefined") {
@@ -88,7 +138,7 @@ var usePreferredColorScheme = () => {
88
138
  };
89
139
  }
90
140
  }, []);
91
- return theme;
141
+ return colorSchemePreference === "auto" ? theme : colorSchemePreference;
92
142
  };
93
143
 
94
144
  export {
@@ -99,5 +149,7 @@ export {
99
149
  usePressable,
100
150
  trackTouch,
101
151
  calculateClass,
152
+ VALID_COLOR_SCHEME_PREFS,
153
+ useColorSchemePreferences,
102
154
  usePreferredColorScheme
103
155
  };
@@ -73,7 +73,57 @@ function trackTouch(touch, move, end) {
73
73
 
74
74
  // src/util/index.ts
75
75
  var calculateClass = (...args) => args.filter((a) => !!a).join(" ");
76
+ var COLOR_SCHEME_SETTINGS = "arcane-color-scheme-preference";
77
+ var VALID_COLOR_SCHEME_PREFS = ["auto", "dark", "light"];
78
+ var isValidColorSchemePreference = (value) => {
79
+ return VALID_COLOR_SCHEME_PREFS.includes(value);
80
+ };
81
+ var useColorSchemePreferences = () => {
82
+ if (typeof window === "undefined") {
83
+ return {
84
+ colorSchemePreference: "auto",
85
+ setColorSchemePreference: () => {
86
+ }
87
+ };
88
+ }
89
+ const [preference, setPreference] = _react.useState.call(void 0,
90
+ window.localStorage.getItem(
91
+ COLOR_SCHEME_SETTINGS
92
+ ) || "auto"
93
+ );
94
+ const setColorSchemePreference = (newPreference) => {
95
+ if (!isValidColorSchemePreference(newPreference)) {
96
+ throw new Error(`Invalid color scheme preference: ${newPreference}`);
97
+ }
98
+ window.localStorage.setItem(COLOR_SCHEME_SETTINGS, newPreference);
99
+ window.dispatchEvent(
100
+ new StorageEvent("storage", {
101
+ key: COLOR_SCHEME_SETTINGS,
102
+ newValue: newPreference
103
+ })
104
+ );
105
+ };
106
+ _react.useEffect.call(void 0, () => {
107
+ const onStorageChange = (event) => {
108
+ if (event.key === COLOR_SCHEME_SETTINGS) {
109
+ const newValue = event.newValue;
110
+ if (isValidColorSchemePreference(newValue)) {
111
+ setPreference(newValue);
112
+ }
113
+ }
114
+ };
115
+ window.addEventListener("storage", onStorageChange);
116
+ return () => {
117
+ window.removeEventListener("storage", onStorageChange);
118
+ };
119
+ }, []);
120
+ return {
121
+ colorSchemePreference: isValidColorSchemePreference(preference) ? preference : "auto",
122
+ setColorSchemePreference
123
+ };
124
+ };
76
125
  var usePreferredColorScheme = () => {
126
+ const { colorSchemePreference } = useColorSchemePreferences();
77
127
  const [theme, setTheme] = _react.useState.call(void 0, "light");
78
128
  _react.useEffect.call(void 0, () => {
79
129
  if (typeof window !== "undefined") {
@@ -88,7 +138,7 @@ var usePreferredColorScheme = () => {
88
138
  };
89
139
  }
90
140
  }, []);
91
- return theme;
141
+ return colorSchemePreference === "auto" ? theme : colorSchemePreference;
92
142
  };
93
143
 
94
144
 
@@ -100,4 +150,6 @@ var usePreferredColorScheme = () => {
100
150
 
101
151
 
102
152
 
103
- exports.__export = __export; exports.switchToMouseMode = switchToMouseMode; exports.switchToTouchMode = switchToTouchMode; exports.initialiseListeners = initialiseListeners; exports.usePressable = usePressable; exports.trackTouch = trackTouch; exports.calculateClass = calculateClass; exports.usePreferredColorScheme = usePreferredColorScheme;
153
+
154
+
155
+ exports.__export = __export; exports.switchToMouseMode = switchToMouseMode; exports.switchToTouchMode = switchToTouchMode; exports.initialiseListeners = initialiseListeners; exports.usePressable = usePressable; exports.trackTouch = trackTouch; exports.calculateClass = calculateClass; exports.VALID_COLOR_SCHEME_PREFS = VALID_COLOR_SCHEME_PREFS; exports.useColorSchemePreferences = useColorSchemePreferences; exports.usePreferredColorScheme = usePreferredColorScheme;
@@ -1,11 +1,11 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
3
 
4
- var _chunk7VTNOX5Ojs = require('./chunk-7VTNOX5O.js');
4
+ var _chunkTMN35K5Yjs = require('./chunk-TMN35K5Y.js');
5
5
 
6
6
  // src/components/core/index.ts
7
7
  var core_exports = {};
8
- _chunk7VTNOX5Ojs.__export.call(void 0, core_exports, {
8
+ _chunkTMN35K5Yjs.__export.call(void 0, core_exports, {
9
9
  Icon: () => Icon,
10
10
  TRANSPARENCY_SVG: () => TRANSPARENCY_SVG,
11
11
  TRANSPARENCY_SVG_URI: () => TRANSPARENCY_SVG_URI
@@ -31,7 +31,7 @@ var Span = _styledcomponents.styled.span`
31
31
  'wght' 300,
32
32
  'GRAD' -25;
33
33
  `;
34
- var Icon = ({ icon, ...props }) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Span, { className: _chunk7VTNOX5Ojs.calculateClass.call(void 0, props.className, ICON_CLASS), ...props, children: icon });
34
+ var Icon = ({ icon, ...props }) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Span, { className: _chunkTMN35K5Yjs.calculateClass.call(void 0, props.className, ICON_CLASS), ...props, children: icon });
35
35
 
36
36
  // src/components/core/index.ts
37
37
  var TRANSPARENCY_SVG = `
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunk7VTNOX5Ojs = require('./chunk-7VTNOX5O.js');
3
+ var _chunkTMN35K5Yjs = require('./chunk-TMN35K5Y.js');
4
4
 
5
5
  // src/styling.tsx
6
6
 
@@ -195,7 +195,7 @@ var touchIndicatorTouching = _styledcomponents.css`
195
195
  transition: border-color 0s;
196
196
  `;
197
197
  var PreferredThemeProvider = ({ dark, light, children }) => {
198
- const theme = _chunk7VTNOX5Ojs.usePreferredColorScheme.call(void 0, );
198
+ const theme = _chunkTMN35K5Yjs.usePreferredColorScheme.call(void 0, );
199
199
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _styledcomponents.ThemeProvider, { theme: theme === "dark" ? dark : light, children });
200
200
  };
201
201
 
@@ -2,10 +2,10 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkT3QSZARMjs = require('../../chunk-T3QSZARM.js');
6
- require('../../chunk-7VTNOX5O.js');
5
+ var _chunkUHFE2X4Vjs = require('../../chunk-UHFE2X4V.js');
6
+ require('../../chunk-TMN35K5Y.js');
7
7
 
8
8
 
9
9
 
10
10
 
11
- exports.Icon = _chunkT3QSZARMjs.Icon; exports.TRANSPARENCY_SVG = _chunkT3QSZARMjs.TRANSPARENCY_SVG; exports.TRANSPARENCY_SVG_URI = _chunkT3QSZARMjs.TRANSPARENCY_SVG_URI;
11
+ exports.Icon = _chunkUHFE2X4Vjs.Icon; exports.TRANSPARENCY_SVG = _chunkUHFE2X4Vjs.TRANSPARENCY_SVG; exports.TRANSPARENCY_SVG_URI = _chunkUHFE2X4Vjs.TRANSPARENCY_SVG_URI;
@@ -2,8 +2,8 @@ import {
2
2
  Icon,
3
3
  TRANSPARENCY_SVG,
4
4
  TRANSPARENCY_SVG_URI
5
- } from "../../chunk-MESQQRK3.mjs";
6
- import "../../chunk-E7JSREGM.mjs";
5
+ } from "../../chunk-GMPDVDSW.mjs";
6
+ import "../../chunk-PTANIWKR.mjs";
7
7
  export {
8
8
  Icon,
9
9
  TRANSPARENCY_SVG,
@@ -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.ClientMessage>(msg: M) => void) | null;
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.ClientMessage>(msg: M) => void) | null;
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
  };
@@ -1,8 +1,8 @@
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
 
5
- var _chunkT3QSZARMjs = require('../chunk-T3QSZARM.js');
5
+ var _chunkUHFE2X4Vjs = require('../chunk-UHFE2X4V.js');
6
6
 
7
7
 
8
8
 
@@ -11,12 +11,12 @@ var _chunkT3QSZARMjs = require('../chunk-T3QSZARM.js');
11
11
 
12
12
 
13
13
 
14
- var _chunkWVMAJYGIjs = require('../chunk-WVMAJYGI.js');
14
+ var _chunkZHJBPEPYjs = require('../chunk-ZHJBPEPY.js');
15
15
 
16
16
 
17
17
 
18
18
 
19
- var _chunk7VTNOX5Ojs = require('../chunk-7VTNOX5O.js');
19
+ var _chunkTMN35K5Yjs = require('../chunk-TMN35K5Y.js');
20
20
 
21
21
  // src/components/index.tsx
22
22
  var _core = require('@arcanejs/protocol/core');
@@ -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 { sendMessage } = _react2.default.useContext(StageContext);
58
- const { touching, handlers } = _chunk7VTNOX5Ojs.usePressable.call(void 0,
59
- () => _optionalChain([sendMessage, 'optionalCall', _ => _({
60
- type: "component-message",
61
- namespace: "core",
62
- componentKey: props.info.key,
63
- component: "button"
64
- })])
65
- );
66
- const { state } = props.info;
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 } = _chunkTMN35K5Yjs.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
- className: _chunk7VTNOX5Ojs.calculateClass.call(void 0,
79
+ className: _chunkTMN35K5Yjs.calculateClass.call(void 0,
71
80
  props.className,
72
- touching || state.state === "pressed" ? TOUCHING_CLASS : null,
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,
@@ -77,7 +87,7 @@ var Button = (props) => {
77
87
  children: [
78
88
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: TOUCH_INDICATOR_CLASS }),
79
89
  /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, ButtonContents, { children: [
80
- props.info.icon && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkT3QSZARMjs.Icon, { icon: props.info.icon }),
90
+ props.info.icon && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkUHFE2X4Vjs.Icon, { icon: props.info.icon }),
81
91
  props.info.text && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ButtonLabel, { children: props.info.text })
82
92
  ] })
83
93
  ]
@@ -85,14 +95,14 @@ var Button = (props) => {
85
95
  );
86
96
  };
87
97
  var StyledButton = _styledcomponents.styled.call(void 0, Button)`
88
- ${_chunkWVMAJYGIjs.rectButton}
98
+ ${_chunkZHJBPEPYjs.rectButton}
89
99
  outline: none;
90
100
  height: 30px;
91
101
  position: relative;
92
102
  overflow: visible;
93
103
 
94
104
  .${TOUCH_INDICATOR_CLASS} {
95
- ${_chunkWVMAJYGIjs.touchIndicatorNormal}
105
+ ${_chunkZHJBPEPYjs.touchIndicatorNormal}
96
106
  }
97
107
 
98
108
  &.${ERROR_CLASS} {
@@ -100,11 +110,11 @@ var StyledButton = _styledcomponents.styled.call(void 0, Button)`
100
110
  border-color: ${(p) => p.theme.colorRed};
101
111
  }
102
112
 
103
- &.${TOUCHING_CLASS} {
104
- ${_chunkWVMAJYGIjs.buttonStateNormalActive}
113
+ &.${TOUCHING_CLASS}, &.${LOADING_CLASS} {
114
+ ${_chunkZHJBPEPYjs.buttonStateNormalActive}
105
115
 
106
116
  .${TOUCH_INDICATOR_CLASS} {
107
- ${_chunkWVMAJYGIjs.touchIndicatorTouching}
117
+ ${_chunkZHJBPEPYjs.touchIndicatorTouching}
108
118
  }
109
119
  }
110
120
  `;
@@ -133,7 +143,7 @@ function nextColor(currentColor) {
133
143
  var LastNestedColor = _react2.default.createContext("dark");
134
144
  var NestedContent = ({ className, children }) => {
135
145
  const color = _react2.default.useContext(LastNestedColor);
136
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: _chunk7VTNOX5Ojs.calculateClass.call(void 0, className, `color-${color}`), children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, LastNestedColor.Provider, { value: nextColor(color), children }) });
146
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: _chunkTMN35K5Yjs.calculateClass.call(void 0, className, `color-${color}`), children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, LastNestedColor.Provider, { value: nextColor(color), children }) });
137
147
  };
138
148
  NestedContent.displayName = "NestedContent";
139
149
  var StyledNestedContent = _styledcomponents.styled.call(void 0, NestedContent)`
@@ -155,7 +165,7 @@ var StyledNestedContent = _styledcomponents.styled.call(void 0, NestedContent)`
155
165
 
156
166
  // src/components/group.tsx
157
167
 
158
- var CollapseIcon = _styledcomponents.styled.call(void 0, (0, _chunkT3QSZARMjs.Icon))({
168
+ var CollapseIcon = _styledcomponents.styled.call(void 0, (0, _chunkUHFE2X4Vjs.Icon))({
159
169
  cursor: "pointer"
160
170
  });
161
171
  var Header = _styledcomponents.styled.div`
@@ -267,7 +277,7 @@ var Group = ({ className, info }) => {
267
277
  const children = /* @__PURE__ */ _jsxruntime.jsx.call(void 0, GroupChildren, { info, children: info.children.map(renderComponent) });
268
278
  const collapsible = !!info.defaultCollapsibleState;
269
279
  const collapsed = info.defaultCollapsibleState ? groupState.isCollapsed(info.key, info.defaultCollapsibleState) : false;
270
- const collapsePressable = _chunk7VTNOX5Ojs.usePressable.call(void 0,
280
+ const collapsePressable = _chunkTMN35K5Yjs.usePressable.call(void 0,
271
281
  () => groupState.toggleCollapsed(info.key)
272
282
  );
273
283
  const showTitle = info.title || info.editableTitle;
@@ -294,11 +304,11 @@ var Group = ({ className, info }) => {
294
304
  };
295
305
  const hasBorder = info.border || displayHeader;
296
306
  const childrenElements = hasBorder ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, StyledNestedContent, { children }) : children;
297
- return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: _chunk7VTNOX5Ojs.calculateClass.call(void 0, className, !hasBorder && "no-border"), children: [
307
+ return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: _chunkTMN35K5Yjs.calculateClass.call(void 0, className, !hasBorder && "no-border"), children: [
298
308
  displayHeader ? /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
299
309
  Header,
300
310
  {
301
- className: _chunk7VTNOX5Ojs.calculateClass.call(void 0,
311
+ className: _chunkTMN35K5Yjs.calculateClass.call(void 0,
302
312
  collapsePressable.touching && "touching",
303
313
  collapsible && collapsed && "collapsed"
304
314
  ),
@@ -321,7 +331,7 @@ var Group = ({ className, info }) => {
321
331
  }
322
332
  ) : /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, EditableTitle, { onClick: () => setEditingTitle(true), children: [
323
333
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: info.title }),
324
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkT3QSZARMjs.Icon, { className: "icon", icon: "edit" })
334
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkUHFE2X4Vjs.Icon, { className: "icon", icon: "edit" })
325
335
  ] }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: info.title })),
326
336
  collapsible ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, CollapseBar, { ...collapsePressable.handlers }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Grow, {}),
327
337
  _optionalChain([info, 'access', _12 => _12.headers, 'optionalAccess', _13 => _13.map, 'call', _14 => _14((h) => h.children.map((c) => renderComponent(c)))])
@@ -365,7 +375,7 @@ var Wrapper = _styledcomponents.styled.div`
365
375
  height: 30px;
366
376
  border-radius: 3px;
367
377
  overflow: hidden;
368
- background: url('${_chunkT3QSZARMjs.TRANSPARENCY_SVG_URI}');
378
+ background: url('${_chunkUHFE2X4Vjs.TRANSPARENCY_SVG_URI}');
369
379
  background-repeat: repeat;
370
380
  background-size: 10px;
371
381
  border: 1px solid ${(p) => p.theme.borderDark};
@@ -378,7 +388,7 @@ var Inner = _styledcomponents.styled.div`
378
388
  width: 100%;
379
389
  height: 100%;
380
390
  `;
381
- var Rect = ({ className, info }) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Wrapper, { className: _chunk7VTNOX5Ojs.calculateClass.call(void 0, className, info.grow && CLS_GROW), children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Inner, { style: { backgroundColor: info.color } }) });
391
+ var Rect = ({ className, info }) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Wrapper, { className: _chunkTMN35K5Yjs.calculateClass.call(void 0, className, info.grow && CLS_GROW), children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Inner, { style: { backgroundColor: info.color } }) });
382
392
 
383
393
  // src/components/slider-button.tsx
384
394
 
@@ -478,7 +488,7 @@ var SliderButton = ({ info, className }) => {
478
488
  touch.pageX
479
489
  );
480
490
  const start = onDown(cursorPosition);
481
- _chunk7VTNOX5Ojs.trackTouch.call(void 0,
491
+ _chunkTMN35K5Yjs.trackTouch.call(void 0,
482
492
  touch,
483
493
  (p) => {
484
494
  const amntDiff = (p.pageX - originalPageX) / OPEN_SLIDER_INNER_WIDTH;
@@ -515,12 +525,12 @@ var SliderButton = ({ info, className }) => {
515
525
  const valueCSSPercent = value ? (value - info.min) / (info.max - info.min) * 100 + "%" : "0";
516
526
  const gradientStops = info.gradient && info.gradient.map((g) => `${g.color} ${g.position * 100}%`);
517
527
  const sliderGradient = gradientStops ? {
518
- background: `linear-gradient(90deg, ${gradientStops.join(", ")}), url(${_chunkT3QSZARMjs.TRANSPARENCY_SVG_URI})`
528
+ background: `linear-gradient(90deg, ${gradientStops.join(", ")}), url(${_chunkUHFE2X4Vjs.TRANSPARENCY_SVG_URI})`
519
529
  } : void 0;
520
530
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
521
531
  "div",
522
532
  {
523
- className: _chunk7VTNOX5Ojs.calculateClass.call(void 0,
533
+ className: _chunkTMN35K5Yjs.calculateClass.call(void 0,
524
534
  className,
525
535
  `state-${state.state}`,
526
536
  info.grow && CLASS_GROW
@@ -548,7 +558,7 @@ var SliderButton = ({ info, className }) => {
548
558
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
549
559
  "div",
550
560
  {
551
- className: _chunk7VTNOX5Ojs.calculateClass.call(void 0,
561
+ className: _chunkTMN35K5Yjs.calculateClass.call(void 0,
552
562
  CLASS_SLIDER_DISPLAY,
553
563
  sliderGradient && CLASS_GRADIENT
554
564
  ),
@@ -585,7 +595,7 @@ var StyledSliderButton = _styledcomponents.styled.call(void 0, SliderButton)`
585
595
  transition: all 200ms;
586
596
  border-radius: 3px;
587
597
  border: 1px solid ${(p) => p.theme.borderDark};
588
- ${_chunkWVMAJYGIjs.buttonStateNormal}
598
+ ${_chunkZHJBPEPYjs.buttonStateNormal}
589
599
 
590
600
  > input {
591
601
  color: ${(p) => p.theme.textNormal};
@@ -654,13 +664,13 @@ var StyledSliderButton = _styledcomponents.styled.call(void 0, SliderButton)`
654
664
  }
655
665
 
656
666
  &:hover {
657
- ${_chunkWVMAJYGIjs.buttonStateNormalHover}
667
+ ${_chunkZHJBPEPYjs.buttonStateNormalHover}
658
668
  }
659
669
  }
660
670
 
661
671
  &.state-mouse-down {
662
672
  > .inner {
663
- ${_chunkWVMAJYGIjs.buttonPressed}
673
+ ${_chunkZHJBPEPYjs.buttonPressed}
664
674
  }
665
675
  }
666
676
 
@@ -728,7 +738,7 @@ var Switch = ({ className, info }) => {
728
738
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
729
739
  "div",
730
740
  {
731
- className: _chunk7VTNOX5Ojs.calculateClass.call(void 0, className, touching && CLASS_TOUCHING),
741
+ className: _chunkTMN35K5Yjs.calculateClass.call(void 0, className, touching && CLASS_TOUCHING),
732
742
  onClick,
733
743
  onTouchStart,
734
744
  onTouchEnd,
@@ -817,12 +827,12 @@ var StyledSwitch = _styledcomponents.styled.call(void 0, Switch)`
817
827
  }
818
828
 
819
829
  .${TOUCH_INDICATOR_CLASS2} {
820
- ${_chunkWVMAJYGIjs.touchIndicatorNormal}
830
+ ${_chunkZHJBPEPYjs.touchIndicatorNormal}
821
831
  }
822
832
 
823
833
  &.${CLASS_TOUCHING} {
824
834
  .${TOUCH_INDICATOR_CLASS2} {
825
- ${_chunkWVMAJYGIjs.touchIndicatorTouching}
835
+ ${_chunkZHJBPEPYjs.touchIndicatorTouching}
826
836
  }
827
837
  }
828
838
  `;
@@ -877,7 +887,7 @@ var Tabs = (props) => {
877
887
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TabList, { children: props.info.tabs.map((tab2, i) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
878
888
  TabItem,
879
889
  {
880
- className: _chunk7VTNOX5Ojs.calculateClass.call(void 0,
890
+ className: _chunkTMN35K5Yjs.calculateClass.call(void 0,
881
891
  touching === i && "touching",
882
892
  currentTab === i && "current"
883
893
  ),
@@ -963,7 +973,7 @@ var SourceData = _styledcomponents.styled.div`
963
973
  align-items: end;
964
974
  justify-content: center;
965
975
  `;
966
- var IndicatorIcon = _styledcomponents.styled.call(void 0, _chunkT3QSZARMjs.Icon)`
976
+ var IndicatorIcon = _styledcomponents.styled.call(void 0, _chunkUHFE2X4Vjs.Icon)`
967
977
  font-size: 40px;
968
978
  `;
969
979
  var Bar = _styledcomponents.styled.div`
@@ -1092,4 +1102,4 @@ var CORE_FRONTEND_COMPONENT_RENDERER = {
1092
1102
 
1093
1103
 
1094
1104
 
1095
- exports.Button = StyledButton; exports.CORE_FRONTEND_COMPONENT_RENDERER = CORE_FRONTEND_COMPONENT_RENDERER; exports.Group = StyledGroup; exports.GroupStateWrapper = GroupStateWrapper; exports.Label = StyledLabel; exports.NestedContent = StyledNestedContent; exports.Rect = Rect; exports.SliderButton = StyledSliderButton; exports.StageContext = StageContext; exports.Switch = StyledSwitch; exports.Tabs = Tabs; exports.TextInput = StyledTextInput; exports.Timeline = Timeline; exports.code = _chunkT3QSZARMjs.core_exports;
1105
+ exports.Button = StyledButton; exports.CORE_FRONTEND_COMPONENT_RENDERER = CORE_FRONTEND_COMPONENT_RENDERER; exports.Group = StyledGroup; exports.GroupStateWrapper = GroupStateWrapper; exports.Label = StyledLabel; exports.NestedContent = StyledNestedContent; exports.Rect = Rect; exports.SliderButton = StyledSliderButton; exports.StageContext = StageContext; exports.Switch = StyledSwitch; exports.Tabs = Tabs; exports.TextInput = StyledTextInput; exports.Timeline = Timeline; exports.code = _chunkUHFE2X4Vjs.core_exports;
@@ -2,7 +2,7 @@ import {
2
2
  Icon,
3
3
  TRANSPARENCY_SVG_URI,
4
4
  core_exports
5
- } from "../chunk-MESQQRK3.mjs";
5
+ } from "../chunk-GMPDVDSW.mjs";
6
6
  import {
7
7
  buttonPressed,
8
8
  buttonStateNormal,
@@ -11,12 +11,12 @@ import {
11
11
  rectButton,
12
12
  touchIndicatorNormal,
13
13
  touchIndicatorTouching
14
- } from "../chunk-BQS6YM6U.mjs";
14
+ } from "../chunk-6XOE7F7U.mjs";
15
15
  import {
16
16
  calculateClass,
17
17
  trackTouch,
18
18
  usePressable
19
- } from "../chunk-E7JSREGM.mjs";
19
+ } from "../chunk-PTANIWKR.mjs";
20
20
 
21
21
  // src/components/index.tsx
22
22
  import { isCoreComponent } from "@arcanejs/protocol/core";
@@ -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 { sendMessage } = React.useContext(StageContext);
58
- const { touching, handlers } = usePressable(
59
- () => sendMessage?.({
60
- type: "component-message",
61
- namespace: "core",
62
- componentKey: props.info.key,
63
- component: "button"
64
- })
65
- );
66
- const { state } = props.info;
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" ? TOUCHING_CLASS : null,
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/styling.js CHANGED
@@ -12,8 +12,8 @@
12
12
 
13
13
 
14
14
 
15
- var _chunkWVMAJYGIjs = require('./chunk-WVMAJYGI.js');
16
- require('./chunk-7VTNOX5O.js');
15
+ var _chunkZHJBPEPYjs = require('./chunk-ZHJBPEPY.js');
16
+ require('./chunk-TMN35K5Y.js');
17
17
 
18
18
 
19
19
 
@@ -28,4 +28,4 @@ require('./chunk-7VTNOX5O.js');
28
28
 
29
29
 
30
30
 
31
- exports.BaseStyle = _chunkWVMAJYGIjs.BaseStyle; exports.DARK_THEME = _chunkWVMAJYGIjs.DARK_THEME; exports.GlobalStyle = _chunkWVMAJYGIjs.GlobalStyle; exports.LIGHT_THEME = _chunkWVMAJYGIjs.LIGHT_THEME; exports.PreferredThemeProvider = _chunkWVMAJYGIjs.PreferredThemeProvider; exports.buttonDisabled = _chunkWVMAJYGIjs.buttonDisabled; exports.buttonPressed = _chunkWVMAJYGIjs.buttonPressed; exports.buttonStateNormal = _chunkWVMAJYGIjs.buttonStateNormal; exports.buttonStateNormalActive = _chunkWVMAJYGIjs.buttonStateNormalActive; exports.buttonStateNormalHover = _chunkWVMAJYGIjs.buttonStateNormalHover; exports.rectButton = _chunkWVMAJYGIjs.rectButton; exports.touchIndicatorNormal = _chunkWVMAJYGIjs.touchIndicatorNormal; exports.touchIndicatorTouching = _chunkWVMAJYGIjs.touchIndicatorTouching;
31
+ exports.BaseStyle = _chunkZHJBPEPYjs.BaseStyle; exports.DARK_THEME = _chunkZHJBPEPYjs.DARK_THEME; exports.GlobalStyle = _chunkZHJBPEPYjs.GlobalStyle; exports.LIGHT_THEME = _chunkZHJBPEPYjs.LIGHT_THEME; exports.PreferredThemeProvider = _chunkZHJBPEPYjs.PreferredThemeProvider; exports.buttonDisabled = _chunkZHJBPEPYjs.buttonDisabled; exports.buttonPressed = _chunkZHJBPEPYjs.buttonPressed; exports.buttonStateNormal = _chunkZHJBPEPYjs.buttonStateNormal; exports.buttonStateNormalActive = _chunkZHJBPEPYjs.buttonStateNormalActive; exports.buttonStateNormalHover = _chunkZHJBPEPYjs.buttonStateNormalHover; exports.rectButton = _chunkZHJBPEPYjs.rectButton; exports.touchIndicatorNormal = _chunkZHJBPEPYjs.touchIndicatorNormal; exports.touchIndicatorTouching = _chunkZHJBPEPYjs.touchIndicatorTouching;
package/dist/styling.mjs CHANGED
@@ -12,8 +12,8 @@ import {
12
12
  rectButton,
13
13
  touchIndicatorNormal,
14
14
  touchIndicatorTouching
15
- } from "./chunk-BQS6YM6U.mjs";
16
- import "./chunk-E7JSREGM.mjs";
15
+ } from "./chunk-6XOE7F7U.mjs";
16
+ import "./chunk-PTANIWKR.mjs";
17
17
  export {
18
18
  BaseStyle,
19
19
  DARK_THEME,
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
 
@@ -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: () => void) => {
4
+ declare const usePressable: (click: () => unknown) => {
5
5
  touching: boolean;
6
6
  handlers: {
7
7
  onClick: React.MouseEventHandler<unknown>;
@@ -19,6 +19,12 @@ declare function trackTouch(touch: React.Touch, move: (pos: {
19
19
  }) => void): void;
20
20
 
21
21
  declare const calculateClass: (...args: (string | undefined | null | false)[]) => string;
22
+ declare const VALID_COLOR_SCHEME_PREFS: readonly ["auto", "dark", "light"];
23
+ type ColorSchemePreference = (typeof VALID_COLOR_SCHEME_PREFS)[number];
24
+ declare const useColorSchemePreferences: () => {
25
+ colorSchemePreference: "dark" | "light" | "auto";
26
+ setColorSchemePreference: (newPreference: ColorSchemePreference) => void;
27
+ };
22
28
  declare const usePreferredColorScheme: () => 'dark' | 'light';
23
29
 
24
- export { calculateClass, initialiseListeners, switchToMouseMode, switchToTouchMode, trackTouch, usePreferredColorScheme, usePressable };
30
+ export { VALID_COLOR_SCHEME_PREFS, calculateClass, initialiseListeners, switchToMouseMode, switchToTouchMode, trackTouch, useColorSchemePreferences, usePreferredColorScheme, usePressable };
@@ -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: () => void) => {
4
+ declare const usePressable: (click: () => unknown) => {
5
5
  touching: boolean;
6
6
  handlers: {
7
7
  onClick: React.MouseEventHandler<unknown>;
@@ -19,6 +19,12 @@ declare function trackTouch(touch: React.Touch, move: (pos: {
19
19
  }) => void): void;
20
20
 
21
21
  declare const calculateClass: (...args: (string | undefined | null | false)[]) => string;
22
+ declare const VALID_COLOR_SCHEME_PREFS: readonly ["auto", "dark", "light"];
23
+ type ColorSchemePreference = (typeof VALID_COLOR_SCHEME_PREFS)[number];
24
+ declare const useColorSchemePreferences: () => {
25
+ colorSchemePreference: "dark" | "light" | "auto";
26
+ setColorSchemePreference: (newPreference: ColorSchemePreference) => void;
27
+ };
22
28
  declare const usePreferredColorScheme: () => 'dark' | 'light';
23
29
 
24
- export { calculateClass, initialiseListeners, switchToMouseMode, switchToTouchMode, trackTouch, usePreferredColorScheme, usePressable };
30
+ export { VALID_COLOR_SCHEME_PREFS, calculateClass, initialiseListeners, switchToMouseMode, switchToTouchMode, trackTouch, useColorSchemePreferences, usePreferredColorScheme, usePressable };
@@ -6,13 +6,17 @@
6
6
 
7
7
 
8
8
 
9
- var _chunk7VTNOX5Ojs = require('../chunk-7VTNOX5O.js');
10
9
 
11
10
 
11
+ var _chunkTMN35K5Yjs = require('../chunk-TMN35K5Y.js');
12
12
 
13
13
 
14
14
 
15
15
 
16
16
 
17
17
 
18
- exports.calculateClass = _chunk7VTNOX5Ojs.calculateClass; exports.initialiseListeners = _chunk7VTNOX5Ojs.initialiseListeners; exports.switchToMouseMode = _chunk7VTNOX5Ojs.switchToMouseMode; exports.switchToTouchMode = _chunk7VTNOX5Ojs.switchToTouchMode; exports.trackTouch = _chunk7VTNOX5Ojs.trackTouch; exports.usePreferredColorScheme = _chunk7VTNOX5Ojs.usePreferredColorScheme; exports.usePressable = _chunk7VTNOX5Ojs.usePressable;
18
+
19
+
20
+
21
+
22
+ exports.VALID_COLOR_SCHEME_PREFS = _chunkTMN35K5Yjs.VALID_COLOR_SCHEME_PREFS; exports.calculateClass = _chunkTMN35K5Yjs.calculateClass; exports.initialiseListeners = _chunkTMN35K5Yjs.initialiseListeners; exports.switchToMouseMode = _chunkTMN35K5Yjs.switchToMouseMode; exports.switchToTouchMode = _chunkTMN35K5Yjs.switchToTouchMode; exports.trackTouch = _chunkTMN35K5Yjs.trackTouch; exports.useColorSchemePreferences = _chunkTMN35K5Yjs.useColorSchemePreferences; exports.usePreferredColorScheme = _chunkTMN35K5Yjs.usePreferredColorScheme; exports.usePressable = _chunkTMN35K5Yjs.usePressable;
@@ -1,18 +1,22 @@
1
1
  import {
2
+ VALID_COLOR_SCHEME_PREFS,
2
3
  calculateClass,
3
4
  initialiseListeners,
4
5
  switchToMouseMode,
5
6
  switchToTouchMode,
6
7
  trackTouch,
8
+ useColorSchemePreferences,
7
9
  usePreferredColorScheme,
8
10
  usePressable
9
- } from "../chunk-E7JSREGM.mjs";
11
+ } from "../chunk-PTANIWKR.mjs";
10
12
  export {
13
+ VALID_COLOR_SCHEME_PREFS,
11
14
  calculateClass,
12
15
  initialiseListeners,
13
16
  switchToMouseMode,
14
17
  switchToTouchMode,
15
18
  trackTouch,
19
+ useColorSchemePreferences,
16
20
  usePreferredColorScheme,
17
21
  usePressable
18
22
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcanejs/toolkit-frontend",
3
- "version": "0.6.1",
3
+ "version": "0.8.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/arcanejs/arcanejs.git"
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.6.0"
65
+ "@arcanejs/protocol": "^0.7.0"
66
66
  },
67
67
  "files": [
68
68
  "dist"