@arcanejs/react-toolkit 0.1.4 → 0.2.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 +2 -2
- package/dist/data.d.mts +45 -0
- package/dist/data.d.ts +45 -0
- package/dist/data.js +203 -0
- package/dist/data.mjs +182 -0
- package/dist/index.d.mts +35 -21
- package/dist/index.d.ts +35 -21
- package/dist/index.js +35 -20664
- package/dist/index.mjs +37 -20695
- package/package.json +22 -6
- package/docs/architecture.svg +0 -271
- package/docs/example-controller.png +0 -0
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ The UI has also been designed primarily with touch devices in mind,
|
|
|
15
15
|
but also works well with a cursor and keyboard.
|
|
16
16
|
|
|
17
17
|
<p align="center">
|
|
18
|
-
<img src="
|
|
18
|
+
<img src="https://raw.githubusercontent.com/arcanejs/arcanejs/main/packages/react-toolkit/docs/architecture.svg" alt="Architecture Diagram">
|
|
19
19
|
</p>
|
|
20
20
|
|
|
21
21
|
## What
|
|
@@ -114,7 +114,7 @@ ToolkitRenderer.render(<ControlPanel />, toolkit);
|
|
|
114
114
|
You would then be able to access the following control panel
|
|
115
115
|
from [localhost:3000](http://localhost:3000):
|
|
116
116
|
|
|
117
|
-

|
|
118
118
|
|
|
119
119
|
Please note:
|
|
120
120
|
|
package/dist/data.d.mts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ReactNode, FC, Context } from 'react';
|
|
2
|
+
import { ZodType } from 'zod';
|
|
3
|
+
|
|
4
|
+
type ProviderProps = {
|
|
5
|
+
path: string;
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
};
|
|
8
|
+
type DataFileUpdater<T> = (update: (current: T) => T) => void;
|
|
9
|
+
type DataFileContext<T> = {
|
|
10
|
+
data: T;
|
|
11
|
+
updateData: DataFileUpdater<T>;
|
|
12
|
+
/**
|
|
13
|
+
* Can be called to force an attempt to re-save the data to disk
|
|
14
|
+
*/
|
|
15
|
+
saveData: () => void;
|
|
16
|
+
/**
|
|
17
|
+
* If an error has ocurred in the last operation (e.g. load or save,
|
|
18
|
+
* then this will be set to that error).
|
|
19
|
+
*
|
|
20
|
+
* Can be used for example to re-prompt users to save data.
|
|
21
|
+
*/
|
|
22
|
+
error: unknown;
|
|
23
|
+
};
|
|
24
|
+
type DataFile<T> = {
|
|
25
|
+
Provider: FC<ProviderProps>;
|
|
26
|
+
context: Context<DataFileContext<T>>;
|
|
27
|
+
};
|
|
28
|
+
type DataFileProps<T> = {
|
|
29
|
+
schema: ZodType<T>;
|
|
30
|
+
defaultValue: T;
|
|
31
|
+
/**
|
|
32
|
+
* When the file path changes and the file does not yet exist,
|
|
33
|
+
* should the previous data be stored in the new file
|
|
34
|
+
* or should the new file be reset to the default value?
|
|
35
|
+
*
|
|
36
|
+
* @default 'defaultValue'
|
|
37
|
+
*/
|
|
38
|
+
onPathChange?: 'transfer' | 'defaultValue';
|
|
39
|
+
};
|
|
40
|
+
declare function useDataFileData<T>(dataFile: DataFile<T>): T;
|
|
41
|
+
declare function useDataFileUpdater<T>(dataFile: DataFile<T>): DataFileUpdater<T>;
|
|
42
|
+
declare function useDataFile<T>(dataFile: DataFile<T>): DataFileContext<T>;
|
|
43
|
+
declare function createDataFileSpec<T>({ schema, defaultValue, onPathChange, }: DataFileProps<T>): DataFile<T>;
|
|
44
|
+
|
|
45
|
+
export { type ProviderProps, createDataFileSpec, useDataFile, useDataFileData, useDataFileUpdater };
|
package/dist/data.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ReactNode, FC, Context } from 'react';
|
|
2
|
+
import { ZodType } from 'zod';
|
|
3
|
+
|
|
4
|
+
type ProviderProps = {
|
|
5
|
+
path: string;
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
};
|
|
8
|
+
type DataFileUpdater<T> = (update: (current: T) => T) => void;
|
|
9
|
+
type DataFileContext<T> = {
|
|
10
|
+
data: T;
|
|
11
|
+
updateData: DataFileUpdater<T>;
|
|
12
|
+
/**
|
|
13
|
+
* Can be called to force an attempt to re-save the data to disk
|
|
14
|
+
*/
|
|
15
|
+
saveData: () => void;
|
|
16
|
+
/**
|
|
17
|
+
* If an error has ocurred in the last operation (e.g. load or save,
|
|
18
|
+
* then this will be set to that error).
|
|
19
|
+
*
|
|
20
|
+
* Can be used for example to re-prompt users to save data.
|
|
21
|
+
*/
|
|
22
|
+
error: unknown;
|
|
23
|
+
};
|
|
24
|
+
type DataFile<T> = {
|
|
25
|
+
Provider: FC<ProviderProps>;
|
|
26
|
+
context: Context<DataFileContext<T>>;
|
|
27
|
+
};
|
|
28
|
+
type DataFileProps<T> = {
|
|
29
|
+
schema: ZodType<T>;
|
|
30
|
+
defaultValue: T;
|
|
31
|
+
/**
|
|
32
|
+
* When the file path changes and the file does not yet exist,
|
|
33
|
+
* should the previous data be stored in the new file
|
|
34
|
+
* or should the new file be reset to the default value?
|
|
35
|
+
*
|
|
36
|
+
* @default 'defaultValue'
|
|
37
|
+
*/
|
|
38
|
+
onPathChange?: 'transfer' | 'defaultValue';
|
|
39
|
+
};
|
|
40
|
+
declare function useDataFileData<T>(dataFile: DataFile<T>): T;
|
|
41
|
+
declare function useDataFileUpdater<T>(dataFile: DataFile<T>): DataFileUpdater<T>;
|
|
42
|
+
declare function useDataFile<T>(dataFile: DataFile<T>): DataFileContext<T>;
|
|
43
|
+
declare function createDataFileSpec<T>({ schema, defaultValue, onPathChange, }: DataFileProps<T>): DataFile<T>;
|
|
44
|
+
|
|
45
|
+
export { type ProviderProps, createDataFileSpec, useDataFile, useDataFileData, useDataFileUpdater };
|
package/dist/data.js
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/data.tsx
|
|
21
|
+
var data_exports = {};
|
|
22
|
+
__export(data_exports, {
|
|
23
|
+
createDataFileSpec: () => createDataFileSpec,
|
|
24
|
+
useDataFile: () => useDataFile,
|
|
25
|
+
useDataFileData: () => useDataFileData,
|
|
26
|
+
useDataFileUpdater: () => useDataFileUpdater
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(data_exports);
|
|
29
|
+
var import_fs = require("fs");
|
|
30
|
+
var import_react = require("react");
|
|
31
|
+
var import_lodash = require("lodash");
|
|
32
|
+
var import_path = require("path");
|
|
33
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
34
|
+
function useDataFileData(dataFile) {
|
|
35
|
+
return (0, import_react.useContext)(dataFile.context).data;
|
|
36
|
+
}
|
|
37
|
+
function useDataFileUpdater(dataFile) {
|
|
38
|
+
return (0, import_react.useContext)(dataFile.context).updateData;
|
|
39
|
+
}
|
|
40
|
+
function useDataFile(dataFile) {
|
|
41
|
+
return (0, import_react.useContext)(dataFile.context);
|
|
42
|
+
}
|
|
43
|
+
function createDataFileSpec({
|
|
44
|
+
schema,
|
|
45
|
+
defaultValue,
|
|
46
|
+
onPathChange = "defaultValue"
|
|
47
|
+
}) {
|
|
48
|
+
const context = (0, import_react.createContext)({
|
|
49
|
+
data: defaultValue,
|
|
50
|
+
updateData: () => {
|
|
51
|
+
throw new Error("Data file provider not used");
|
|
52
|
+
},
|
|
53
|
+
saveData: () => {
|
|
54
|
+
throw new Error("Data file provider not used");
|
|
55
|
+
},
|
|
56
|
+
error: void 0
|
|
57
|
+
});
|
|
58
|
+
const Provider = ({ path, children }) => {
|
|
59
|
+
const state = (0, import_react.useRef)({
|
|
60
|
+
path: null,
|
|
61
|
+
data: void 0,
|
|
62
|
+
previousData: void 0,
|
|
63
|
+
state: {
|
|
64
|
+
state: "saved"
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
const [data, setData] = (0, import_react.useState)({
|
|
68
|
+
status: "loading"
|
|
69
|
+
});
|
|
70
|
+
const updateDataFromState = (0, import_react.useMemo)(
|
|
71
|
+
() => () => {
|
|
72
|
+
const data2 = state.current.data;
|
|
73
|
+
if (state.current.state.state === "error") {
|
|
74
|
+
setData({
|
|
75
|
+
status: "error",
|
|
76
|
+
error: state.current.state.error,
|
|
77
|
+
data: data2
|
|
78
|
+
});
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (data2 === void 0) {
|
|
82
|
+
setData({
|
|
83
|
+
status: "loading"
|
|
84
|
+
});
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
setData({
|
|
88
|
+
status: "ready",
|
|
89
|
+
data: data2
|
|
90
|
+
});
|
|
91
|
+
},
|
|
92
|
+
[]
|
|
93
|
+
);
|
|
94
|
+
const requestFileWriteToDisk = (0, import_react.useMemo)(
|
|
95
|
+
() => (0, import_lodash.throttle)(
|
|
96
|
+
async () => {
|
|
97
|
+
if (state.current.state.state === "saved") {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const currentPath = state.current.path;
|
|
101
|
+
const currentData = state.current.data;
|
|
102
|
+
if (!currentPath || currentData === void 0) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
const json = JSON.stringify(currentData, null, 2);
|
|
107
|
+
await import_fs.promises.mkdir((0, import_path.dirname)(currentPath), { recursive: true });
|
|
108
|
+
await import_fs.promises.writeFile(currentPath, json, "utf8");
|
|
109
|
+
if (state.current.path === currentPath && state.current.data === currentData) {
|
|
110
|
+
state.current.state = { state: "saved" };
|
|
111
|
+
}
|
|
112
|
+
} catch (error) {
|
|
113
|
+
if (state.current.path === currentPath && state.current.data === currentData) {
|
|
114
|
+
state.current.state = { state: "error", error };
|
|
115
|
+
updateDataFromState();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
500,
|
|
120
|
+
{
|
|
121
|
+
// Write leading so that we always write to disk quickly when
|
|
122
|
+
// only single things have changed
|
|
123
|
+
leading: true,
|
|
124
|
+
// Trailing is important otherwise we may lose data
|
|
125
|
+
trailing: true
|
|
126
|
+
}
|
|
127
|
+
),
|
|
128
|
+
[]
|
|
129
|
+
);
|
|
130
|
+
(0, import_react.useEffect)(() => {
|
|
131
|
+
state.current = {
|
|
132
|
+
path,
|
|
133
|
+
data: void 0,
|
|
134
|
+
previousData: state.current.data ?? state.current.previousData,
|
|
135
|
+
state: {
|
|
136
|
+
state: "saved"
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
import_fs.promises.readFile(path, "utf8").then((data2) => {
|
|
140
|
+
const parsedData = schema.parse(JSON.parse(data2));
|
|
141
|
+
if (state.current.path === path) {
|
|
142
|
+
state.current.data = parsedData;
|
|
143
|
+
state.current.state = { state: "saved" };
|
|
144
|
+
updateDataFromState();
|
|
145
|
+
}
|
|
146
|
+
}).catch((error) => {
|
|
147
|
+
if (state.current.path !== path) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (error.code === "ENOENT") {
|
|
151
|
+
console.log("Creating new file");
|
|
152
|
+
const initialData = onPathChange === "transfer" && state.current.previousData !== void 0 ? state.current.previousData : defaultValue;
|
|
153
|
+
state.current.data = initialData;
|
|
154
|
+
state.current.state = { state: "dirty" };
|
|
155
|
+
requestFileWriteToDisk();
|
|
156
|
+
updateDataFromState();
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
state.current.state = { state: "error", error };
|
|
160
|
+
updateDataFromState();
|
|
161
|
+
});
|
|
162
|
+
}, [path]);
|
|
163
|
+
const updateData = (0, import_react.useMemo)(
|
|
164
|
+
() => (update) => {
|
|
165
|
+
if (state.current.path !== path) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
if (state.current.data === void 0) {
|
|
169
|
+
throw new Error("Attempt to update data before it has been loaded");
|
|
170
|
+
}
|
|
171
|
+
state.current.data = update(state.current.data);
|
|
172
|
+
state.current.state = { state: "dirty" };
|
|
173
|
+
requestFileWriteToDisk();
|
|
174
|
+
updateDataFromState();
|
|
175
|
+
},
|
|
176
|
+
[path]
|
|
177
|
+
);
|
|
178
|
+
const providedContext = (0, import_react.useMemo)(
|
|
179
|
+
() => ({
|
|
180
|
+
data: data.status !== "loading" && data.data !== void 0 ? data.data : defaultValue,
|
|
181
|
+
updateData,
|
|
182
|
+
saveData: requestFileWriteToDisk,
|
|
183
|
+
error: data.status === "error" ? data.error : void 0
|
|
184
|
+
}),
|
|
185
|
+
[data, updateData]
|
|
186
|
+
);
|
|
187
|
+
if (data.status === "loading") {
|
|
188
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: "Loading..." });
|
|
189
|
+
}
|
|
190
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(context.Provider, { value: providedContext, children });
|
|
191
|
+
};
|
|
192
|
+
return {
|
|
193
|
+
Provider,
|
|
194
|
+
context
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
198
|
+
0 && (module.exports = {
|
|
199
|
+
createDataFileSpec,
|
|
200
|
+
useDataFile,
|
|
201
|
+
useDataFileData,
|
|
202
|
+
useDataFileUpdater
|
|
203
|
+
});
|
package/dist/data.mjs
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// src/data.tsx
|
|
2
|
+
import { promises as fs } from "fs";
|
|
3
|
+
import {
|
|
4
|
+
useMemo,
|
|
5
|
+
useContext,
|
|
6
|
+
createContext,
|
|
7
|
+
useState,
|
|
8
|
+
useEffect,
|
|
9
|
+
useRef
|
|
10
|
+
} from "react";
|
|
11
|
+
import { throttle } from "lodash";
|
|
12
|
+
import { dirname } from "path";
|
|
13
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
14
|
+
function useDataFileData(dataFile) {
|
|
15
|
+
return useContext(dataFile.context).data;
|
|
16
|
+
}
|
|
17
|
+
function useDataFileUpdater(dataFile) {
|
|
18
|
+
return useContext(dataFile.context).updateData;
|
|
19
|
+
}
|
|
20
|
+
function useDataFile(dataFile) {
|
|
21
|
+
return useContext(dataFile.context);
|
|
22
|
+
}
|
|
23
|
+
function createDataFileSpec({
|
|
24
|
+
schema,
|
|
25
|
+
defaultValue,
|
|
26
|
+
onPathChange = "defaultValue"
|
|
27
|
+
}) {
|
|
28
|
+
const context = createContext({
|
|
29
|
+
data: defaultValue,
|
|
30
|
+
updateData: () => {
|
|
31
|
+
throw new Error("Data file provider not used");
|
|
32
|
+
},
|
|
33
|
+
saveData: () => {
|
|
34
|
+
throw new Error("Data file provider not used");
|
|
35
|
+
},
|
|
36
|
+
error: void 0
|
|
37
|
+
});
|
|
38
|
+
const Provider = ({ path, children }) => {
|
|
39
|
+
const state = useRef({
|
|
40
|
+
path: null,
|
|
41
|
+
data: void 0,
|
|
42
|
+
previousData: void 0,
|
|
43
|
+
state: {
|
|
44
|
+
state: "saved"
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
const [data, setData] = useState({
|
|
48
|
+
status: "loading"
|
|
49
|
+
});
|
|
50
|
+
const updateDataFromState = useMemo(
|
|
51
|
+
() => () => {
|
|
52
|
+
const data2 = state.current.data;
|
|
53
|
+
if (state.current.state.state === "error") {
|
|
54
|
+
setData({
|
|
55
|
+
status: "error",
|
|
56
|
+
error: state.current.state.error,
|
|
57
|
+
data: data2
|
|
58
|
+
});
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (data2 === void 0) {
|
|
62
|
+
setData({
|
|
63
|
+
status: "loading"
|
|
64
|
+
});
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
setData({
|
|
68
|
+
status: "ready",
|
|
69
|
+
data: data2
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
[]
|
|
73
|
+
);
|
|
74
|
+
const requestFileWriteToDisk = useMemo(
|
|
75
|
+
() => throttle(
|
|
76
|
+
async () => {
|
|
77
|
+
if (state.current.state.state === "saved") {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const currentPath = state.current.path;
|
|
81
|
+
const currentData = state.current.data;
|
|
82
|
+
if (!currentPath || currentData === void 0) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
const json = JSON.stringify(currentData, null, 2);
|
|
87
|
+
await fs.mkdir(dirname(currentPath), { recursive: true });
|
|
88
|
+
await fs.writeFile(currentPath, json, "utf8");
|
|
89
|
+
if (state.current.path === currentPath && state.current.data === currentData) {
|
|
90
|
+
state.current.state = { state: "saved" };
|
|
91
|
+
}
|
|
92
|
+
} catch (error) {
|
|
93
|
+
if (state.current.path === currentPath && state.current.data === currentData) {
|
|
94
|
+
state.current.state = { state: "error", error };
|
|
95
|
+
updateDataFromState();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
500,
|
|
100
|
+
{
|
|
101
|
+
// Write leading so that we always write to disk quickly when
|
|
102
|
+
// only single things have changed
|
|
103
|
+
leading: true,
|
|
104
|
+
// Trailing is important otherwise we may lose data
|
|
105
|
+
trailing: true
|
|
106
|
+
}
|
|
107
|
+
),
|
|
108
|
+
[]
|
|
109
|
+
);
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
state.current = {
|
|
112
|
+
path,
|
|
113
|
+
data: void 0,
|
|
114
|
+
previousData: state.current.data ?? state.current.previousData,
|
|
115
|
+
state: {
|
|
116
|
+
state: "saved"
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
fs.readFile(path, "utf8").then((data2) => {
|
|
120
|
+
const parsedData = schema.parse(JSON.parse(data2));
|
|
121
|
+
if (state.current.path === path) {
|
|
122
|
+
state.current.data = parsedData;
|
|
123
|
+
state.current.state = { state: "saved" };
|
|
124
|
+
updateDataFromState();
|
|
125
|
+
}
|
|
126
|
+
}).catch((error) => {
|
|
127
|
+
if (state.current.path !== path) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (error.code === "ENOENT") {
|
|
131
|
+
console.log("Creating new file");
|
|
132
|
+
const initialData = onPathChange === "transfer" && state.current.previousData !== void 0 ? state.current.previousData : defaultValue;
|
|
133
|
+
state.current.data = initialData;
|
|
134
|
+
state.current.state = { state: "dirty" };
|
|
135
|
+
requestFileWriteToDisk();
|
|
136
|
+
updateDataFromState();
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
state.current.state = { state: "error", error };
|
|
140
|
+
updateDataFromState();
|
|
141
|
+
});
|
|
142
|
+
}, [path]);
|
|
143
|
+
const updateData = useMemo(
|
|
144
|
+
() => (update) => {
|
|
145
|
+
if (state.current.path !== path) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (state.current.data === void 0) {
|
|
149
|
+
throw new Error("Attempt to update data before it has been loaded");
|
|
150
|
+
}
|
|
151
|
+
state.current.data = update(state.current.data);
|
|
152
|
+
state.current.state = { state: "dirty" };
|
|
153
|
+
requestFileWriteToDisk();
|
|
154
|
+
updateDataFromState();
|
|
155
|
+
},
|
|
156
|
+
[path]
|
|
157
|
+
);
|
|
158
|
+
const providedContext = useMemo(
|
|
159
|
+
() => ({
|
|
160
|
+
data: data.status !== "loading" && data.data !== void 0 ? data.data : defaultValue,
|
|
161
|
+
updateData,
|
|
162
|
+
saveData: requestFileWriteToDisk,
|
|
163
|
+
error: data.status === "error" ? data.error : void 0
|
|
164
|
+
}),
|
|
165
|
+
[data, updateData]
|
|
166
|
+
);
|
|
167
|
+
if (data.status === "loading") {
|
|
168
|
+
return /* @__PURE__ */ jsx(Fragment, { children: "Loading..." });
|
|
169
|
+
}
|
|
170
|
+
return /* @__PURE__ */ jsx(context.Provider, { value: providedContext, children });
|
|
171
|
+
};
|
|
172
|
+
return {
|
|
173
|
+
Provider,
|
|
174
|
+
context
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
export {
|
|
178
|
+
createDataFileSpec,
|
|
179
|
+
useDataFile,
|
|
180
|
+
useDataFileData,
|
|
181
|
+
useDataFileUpdater
|
|
182
|
+
};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,68 +1,82 @@
|
|
|
1
1
|
import * as ld from '@arcanejs/toolkit';
|
|
2
|
-
import { Props as Props$1, Events as Events$1 } from '@arcanejs/toolkit/components/group';
|
|
3
|
-
import { Props, Events } from '@arcanejs/toolkit/components/button';
|
|
4
|
-
import { Props as Props$2 } from '@arcanejs/toolkit/components/label';
|
|
5
|
-
import { Props as Props$3 } from '@arcanejs/toolkit/components/rect';
|
|
6
|
-
import { Props as Props$4, Events as Events$2 } from '@arcanejs/toolkit/components/slider-button';
|
|
7
|
-
import { Props as Props$5, Events as Events$3 } from '@arcanejs/toolkit/components/switch';
|
|
8
|
-
import { TabProps, TabsProps } from '@arcanejs/toolkit/components/tabs';
|
|
9
|
-
import { Props as Props$6, Events as Events$4 } from '@arcanejs/toolkit/components/text-input';
|
|
10
|
-
import { Props as Props$7 } from '@arcanejs/toolkit/components/timeline';
|
|
2
|
+
import { Props as Props$1, Events as Events$1, Group as Group$1, GroupHeader as GroupHeader$1 } from '@arcanejs/toolkit/components/group';
|
|
3
|
+
import { Props, Events, Button as Button$1 } from '@arcanejs/toolkit/components/button';
|
|
4
|
+
import { Props as Props$2, Label as Label$1 } from '@arcanejs/toolkit/components/label';
|
|
5
|
+
import { Props as Props$3, Rect as Rect$1 } from '@arcanejs/toolkit/components/rect';
|
|
6
|
+
import { Props as Props$4, Events as Events$2, SliderButton as SliderButton$1 } from '@arcanejs/toolkit/components/slider-button';
|
|
7
|
+
import { Props as Props$5, Events as Events$3, Switch as Switch$1 } from '@arcanejs/toolkit/components/switch';
|
|
8
|
+
import { TabProps, Tab as Tab$1, TabsProps, Tabs as Tabs$1 } from '@arcanejs/toolkit/components/tabs';
|
|
9
|
+
import { Props as Props$6, Events as Events$4, TextInput as TextInput$1 } from '@arcanejs/toolkit/components/text-input';
|
|
10
|
+
import { Props as Props$7, Timeline as Timeline$1 } from '@arcanejs/toolkit/components/timeline';
|
|
11
11
|
import * as React from 'react';
|
|
12
|
+
import { Ref } from 'react';
|
|
12
13
|
|
|
13
|
-
type
|
|
14
|
+
type Child = JSX.Element | string | null | undefined;
|
|
15
|
+
type Children = Child | Child[];
|
|
14
16
|
interface LightDeskIntrinsicElements {
|
|
15
17
|
button: Props & {
|
|
16
18
|
children?: never;
|
|
17
19
|
onClick?: Events['click'];
|
|
20
|
+
ref?: Ref<Button$1>;
|
|
18
21
|
};
|
|
19
22
|
group: Props$1 & {
|
|
20
23
|
children?: Children;
|
|
21
24
|
onTitleChanged?: Events$1['title-changed'];
|
|
25
|
+
ref?: Ref<Group$1>;
|
|
22
26
|
};
|
|
23
27
|
'group-header': {
|
|
24
28
|
children?: Children;
|
|
29
|
+
ref?: Ref<GroupHeader$1>;
|
|
25
30
|
};
|
|
26
31
|
label: Props$2 & {
|
|
27
32
|
children?: never;
|
|
33
|
+
ref?: Ref<Label$1>;
|
|
28
34
|
};
|
|
29
35
|
rect: Props$3 & {
|
|
30
36
|
children?: never;
|
|
37
|
+
ref?: Ref<Rect$1>;
|
|
31
38
|
};
|
|
32
39
|
'slider-button': Props$4 & {
|
|
33
40
|
children?: never;
|
|
34
41
|
onChange?: Events$2['change'];
|
|
42
|
+
ref?: Ref<SliderButton$1>;
|
|
35
43
|
};
|
|
36
44
|
switch: Props$5 & {
|
|
37
45
|
children?: never;
|
|
38
46
|
onChange?: Events$3['change'];
|
|
47
|
+
ref?: Ref<Switch$1>;
|
|
39
48
|
};
|
|
40
49
|
tab: TabProps & {
|
|
41
50
|
children?: JSX.Element | string;
|
|
51
|
+
ref?: Ref<Tab$1>;
|
|
42
52
|
};
|
|
43
53
|
tabs: TabsProps & {
|
|
44
54
|
children?: JSX.Element | JSX.Element[];
|
|
55
|
+
ref?: Ref<Tabs$1>;
|
|
45
56
|
};
|
|
46
57
|
'text-input': Props$6 & {
|
|
47
58
|
children?: JSX.Element | JSX.Element[];
|
|
48
59
|
onChange?: Events$4['change'];
|
|
60
|
+
ref?: Ref<TextInput$1>;
|
|
49
61
|
};
|
|
50
62
|
timeline: Props$7 & {
|
|
51
63
|
children?: never;
|
|
64
|
+
ref?: Ref<Timeline$1>;
|
|
52
65
|
};
|
|
53
66
|
}
|
|
54
67
|
|
|
55
|
-
|
|
56
|
-
declare const
|
|
57
|
-
declare const
|
|
58
|
-
declare const
|
|
59
|
-
declare const
|
|
60
|
-
declare const
|
|
61
|
-
declare const
|
|
62
|
-
declare const
|
|
63
|
-
declare const
|
|
64
|
-
declare const
|
|
65
|
-
declare const
|
|
68
|
+
type ComponentWithRef<T, P> = React.ForwardRefExoticComponent<React.PropsWithoutRef<P> & React.RefAttributes<T>>;
|
|
69
|
+
declare const Button: ComponentWithRef<Button$1, LightDeskIntrinsicElements['button']>;
|
|
70
|
+
declare const Group: ComponentWithRef<Group$1, LightDeskIntrinsicElements['group']>;
|
|
71
|
+
declare const GroupHeader: ComponentWithRef<GroupHeader$1, LightDeskIntrinsicElements['group-header']>;
|
|
72
|
+
declare const Label: ComponentWithRef<Label$1, LightDeskIntrinsicElements['label']>;
|
|
73
|
+
declare const Rect: ComponentWithRef<Rect$1, LightDeskIntrinsicElements['rect']>;
|
|
74
|
+
declare const SliderButton: ComponentWithRef<SliderButton$1, LightDeskIntrinsicElements['slider-button']>;
|
|
75
|
+
declare const Switch: ComponentWithRef<Switch$1, LightDeskIntrinsicElements['switch']>;
|
|
76
|
+
declare const Tab: ComponentWithRef<Tab$1, LightDeskIntrinsicElements['tab']>;
|
|
77
|
+
declare const Tabs: ComponentWithRef<Tabs$1, LightDeskIntrinsicElements['tabs']>;
|
|
78
|
+
declare const TextInput: ComponentWithRef<TextInput$1, LightDeskIntrinsicElements['text-input']>;
|
|
79
|
+
declare const Timeline: ComponentWithRef<Timeline$1, LightDeskIntrinsicElements['timeline']>;
|
|
66
80
|
|
|
67
81
|
declare const ToolkitRenderer: {
|
|
68
82
|
renderGroup: (component: JSX.Element, container: ld.Group) => void;
|