@arcanejs/react-toolkit 0.3.1 → 0.4.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/dist/chunk-RT2VSMJL.js +13 -0
- package/dist/chunk-TOGR56FN.mjs +13 -0
- package/dist/data.js +48 -62
- package/dist/data.mjs +10 -1
- package/dist/logging.d.mts +7 -0
- package/dist/logging.d.ts +7 -0
- package/dist/logging.js +8 -0
- package/dist/logging.mjs +8 -0
- package/package.json +10 -3
- package/dist/index.d.mts +0 -86
- package/dist/index.d.ts +0 -86
- package/dist/index.js +0 -290
- package/dist/index.mjs +0 -244
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/logging.ts
|
|
2
|
+
var _react = require('react');
|
|
3
|
+
var LoggerContext = _react.createContext.call(void 0, () => {
|
|
4
|
+
throw new Error("LoggerContext not provided");
|
|
5
|
+
});
|
|
6
|
+
var useLogger = () => {
|
|
7
|
+
return _react.useContext.call(void 0, LoggerContext)();
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
exports.LoggerContext = LoggerContext; exports.useLogger = useLogger;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/logging.ts
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
var LoggerContext = createContext(() => {
|
|
4
|
+
throw new Error("LoggerContext not provided");
|
|
5
|
+
});
|
|
6
|
+
var useLogger = () => {
|
|
7
|
+
return useContext(LoggerContext)();
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
LoggerContext,
|
|
12
|
+
useLogger
|
|
13
|
+
};
|
package/dist/data.js
CHANGED
|
@@ -1,46 +1,28 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
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);
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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
|
+
|
|
3
|
+
var _chunkRT2VSMJLjs = require('./chunk-RT2VSMJL.js');
|
|
19
4
|
|
|
20
5
|
// src/data.tsx
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
var
|
|
32
|
-
var
|
|
33
|
-
var import_lodash = require("lodash");
|
|
34
|
-
var import_path = require("path");
|
|
35
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
6
|
+
var _fs = require('fs');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
var _react = require('react');
|
|
15
|
+
var _lodash = require('lodash');
|
|
16
|
+
var _path = require('path');
|
|
17
|
+
var _jsxruntime = require('react/jsx-runtime');
|
|
36
18
|
function useDataFileData(dataFile) {
|
|
37
|
-
return (0,
|
|
19
|
+
return _react.useContext.call(void 0, dataFile.context).data;
|
|
38
20
|
}
|
|
39
21
|
function useDataFileUpdater(dataFile) {
|
|
40
|
-
return (0,
|
|
22
|
+
return _react.useContext.call(void 0, dataFile.context).updateData;
|
|
41
23
|
}
|
|
42
24
|
function useDataFileContext(dataFile) {
|
|
43
|
-
return (0,
|
|
25
|
+
return _react.useContext.call(void 0, dataFile.context);
|
|
44
26
|
}
|
|
45
27
|
function useDataFile(dataFile, usage) {
|
|
46
28
|
return dataFile.useDataFile(usage);
|
|
@@ -51,7 +33,8 @@ function useDataFileCore({
|
|
|
51
33
|
path,
|
|
52
34
|
onPathChange = "defaultValue"
|
|
53
35
|
}) {
|
|
54
|
-
const
|
|
36
|
+
const log = _chunkRT2VSMJLjs.useLogger.call(void 0, );
|
|
37
|
+
const state = _react.useRef.call(void 0, {
|
|
55
38
|
initialized: false,
|
|
56
39
|
path: null,
|
|
57
40
|
data: void 0,
|
|
@@ -60,7 +43,7 @@ function useDataFileCore({
|
|
|
60
43
|
state: "saved"
|
|
61
44
|
}
|
|
62
45
|
});
|
|
63
|
-
(0,
|
|
46
|
+
_react.useEffect.call(void 0, () => {
|
|
64
47
|
if (!state.current.initialized) {
|
|
65
48
|
state.current.initialized = true;
|
|
66
49
|
} else {
|
|
@@ -69,11 +52,11 @@ function useDataFileCore({
|
|
|
69
52
|
);
|
|
70
53
|
}
|
|
71
54
|
}, [schema, defaultValue]);
|
|
72
|
-
const [data, setData] = (0,
|
|
55
|
+
const [data, setData] = _react.useState.call(void 0, {
|
|
73
56
|
status: "loading",
|
|
74
57
|
data: void 0
|
|
75
58
|
});
|
|
76
|
-
const updateDataFromState = (0,
|
|
59
|
+
const updateDataFromState = _react.useMemo.call(void 0,
|
|
77
60
|
() => () => {
|
|
78
61
|
const data2 = state.current.data;
|
|
79
62
|
if (state.current.state.state === "error") {
|
|
@@ -98,8 +81,8 @@ function useDataFileCore({
|
|
|
98
81
|
},
|
|
99
82
|
[]
|
|
100
83
|
);
|
|
101
|
-
const saveData = (0,
|
|
102
|
-
() => (0,
|
|
84
|
+
const saveData = _react.useMemo.call(void 0,
|
|
85
|
+
() => _lodash.throttle.call(void 0,
|
|
103
86
|
async () => {
|
|
104
87
|
if (state.current.state.state === "saved") {
|
|
105
88
|
return;
|
|
@@ -111,8 +94,8 @@ function useDataFileCore({
|
|
|
111
94
|
}
|
|
112
95
|
try {
|
|
113
96
|
const json = JSON.stringify(currentData, null, 2);
|
|
114
|
-
await
|
|
115
|
-
await
|
|
97
|
+
await _fs.promises.mkdir(_path.dirname.call(void 0, currentPath), { recursive: true });
|
|
98
|
+
await _fs.promises.writeFile(currentPath, json, "utf8");
|
|
116
99
|
if (state.current.path === currentPath && state.current.data === currentData) {
|
|
117
100
|
state.current.state = { state: "saved" };
|
|
118
101
|
}
|
|
@@ -134,17 +117,17 @@ function useDataFileCore({
|
|
|
134
117
|
),
|
|
135
118
|
[]
|
|
136
119
|
);
|
|
137
|
-
(0,
|
|
120
|
+
_react.useEffect.call(void 0, () => {
|
|
138
121
|
state.current = {
|
|
139
122
|
...state.current,
|
|
140
123
|
path,
|
|
141
124
|
data: void 0,
|
|
142
|
-
previousData: state.current.data
|
|
125
|
+
previousData: _nullishCoalesce(state.current.data, () => ( state.current.previousData)),
|
|
143
126
|
state: {
|
|
144
127
|
state: "saved"
|
|
145
128
|
}
|
|
146
129
|
};
|
|
147
|
-
|
|
130
|
+
_fs.promises.readFile(path, "utf8").then((data2) => {
|
|
148
131
|
const parsedData = schema.parse(JSON.parse(data2));
|
|
149
132
|
if (state.current.path === path) {
|
|
150
133
|
state.current.data = parsedData;
|
|
@@ -156,10 +139,14 @@ function useDataFileCore({
|
|
|
156
139
|
return;
|
|
157
140
|
}
|
|
158
141
|
if (error.code === "ENOENT") {
|
|
159
|
-
console.log("Creating new file");
|
|
160
142
|
const initialData = onPathChange === "transfer" && state.current.previousData !== void 0 ? state.current.previousData : defaultValue;
|
|
161
143
|
state.current.data = initialData;
|
|
162
144
|
state.current.state = { state: "dirty" };
|
|
145
|
+
_optionalChain([log, 'optionalAccess', _ => _.info, 'call', _2 => _2(
|
|
146
|
+
"Creating a new file at %s with initial data %o",
|
|
147
|
+
path,
|
|
148
|
+
initialData
|
|
149
|
+
)]);
|
|
163
150
|
saveData();
|
|
164
151
|
updateDataFromState();
|
|
165
152
|
return;
|
|
@@ -168,7 +155,7 @@ function useDataFileCore({
|
|
|
168
155
|
updateDataFromState();
|
|
169
156
|
});
|
|
170
157
|
}, [path, onPathChange]);
|
|
171
|
-
const updateData = (0,
|
|
158
|
+
const updateData = _react.useMemo.call(void 0,
|
|
172
159
|
() => (update) => {
|
|
173
160
|
if (state.current.path !== path) {
|
|
174
161
|
return;
|
|
@@ -193,7 +180,7 @@ function createDataFileDefinition({
|
|
|
193
180
|
schema,
|
|
194
181
|
defaultValue
|
|
195
182
|
}) {
|
|
196
|
-
const context = (0,
|
|
183
|
+
const context = _react.createContext.call(void 0, {
|
|
197
184
|
data: defaultValue,
|
|
198
185
|
updateData: () => {
|
|
199
186
|
throw new Error("Data file provider not used");
|
|
@@ -217,7 +204,7 @@ function createDataFileDefinition({
|
|
|
217
204
|
path,
|
|
218
205
|
onPathChange
|
|
219
206
|
});
|
|
220
|
-
const providedContext = (0,
|
|
207
|
+
const providedContext = _react.useMemo.call(void 0,
|
|
221
208
|
() => ({
|
|
222
209
|
data: data.status !== "loading" && data.data !== void 0 ? data.data : defaultValue,
|
|
223
210
|
updateData,
|
|
@@ -227,9 +214,9 @@ function createDataFileDefinition({
|
|
|
227
214
|
[data, updateData]
|
|
228
215
|
);
|
|
229
216
|
if (data.status === "loading") {
|
|
230
|
-
return /* @__PURE__ */ (0,
|
|
217
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _jsxruntime.Fragment, { children: "Loading..." });
|
|
231
218
|
}
|
|
232
|
-
return /* @__PURE__ */ (0,
|
|
219
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, context.Provider, { value: providedContext, children });
|
|
233
220
|
};
|
|
234
221
|
return {
|
|
235
222
|
Provider,
|
|
@@ -237,12 +224,11 @@ function createDataFileDefinition({
|
|
|
237
224
|
useDataFile: useDataFile2
|
|
238
225
|
};
|
|
239
226
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
});
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
exports.createDataFileDefinition = createDataFileDefinition; exports.useDataFile = useDataFile; exports.useDataFileContext = useDataFileContext; exports.useDataFileCore = useDataFileCore; exports.useDataFileData = useDataFileData; exports.useDataFileUpdater = useDataFileUpdater;
|
package/dist/data.mjs
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useLogger
|
|
3
|
+
} from "./chunk-TOGR56FN.mjs";
|
|
4
|
+
|
|
1
5
|
// src/data.tsx
|
|
2
6
|
import { promises as fs } from "fs";
|
|
3
7
|
import {
|
|
@@ -29,6 +33,7 @@ function useDataFileCore({
|
|
|
29
33
|
path,
|
|
30
34
|
onPathChange = "defaultValue"
|
|
31
35
|
}) {
|
|
36
|
+
const log = useLogger();
|
|
32
37
|
const state = useRef({
|
|
33
38
|
initialized: false,
|
|
34
39
|
path: null,
|
|
@@ -134,10 +139,14 @@ function useDataFileCore({
|
|
|
134
139
|
return;
|
|
135
140
|
}
|
|
136
141
|
if (error.code === "ENOENT") {
|
|
137
|
-
console.log("Creating new file");
|
|
138
142
|
const initialData = onPathChange === "transfer" && state.current.previousData !== void 0 ? state.current.previousData : defaultValue;
|
|
139
143
|
state.current.data = initialData;
|
|
140
144
|
state.current.state = { state: "dirty" };
|
|
145
|
+
log?.info(
|
|
146
|
+
"Creating a new file at %s with initial data %o",
|
|
147
|
+
path,
|
|
148
|
+
initialData
|
|
149
|
+
);
|
|
141
150
|
saveData();
|
|
142
151
|
updateDataFromState();
|
|
143
152
|
return;
|
package/dist/logging.js
ADDED
package/dist/logging.mjs
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcanejs/react-toolkit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Build web-accessible control interfaces for your long-running Node.js processes",
|
|
6
6
|
"keywords": [
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"exports": {
|
|
22
22
|
".": {
|
|
23
|
-
"@arcanejs/source": "./src/index.
|
|
23
|
+
"@arcanejs/source": "./src/index.tsx",
|
|
24
24
|
"import": "./dist/index.mjs",
|
|
25
25
|
"require": "./dist/index.js",
|
|
26
26
|
"types": "./dist/index.d.ts"
|
|
@@ -30,6 +30,12 @@
|
|
|
30
30
|
"import": "./dist/data.mjs",
|
|
31
31
|
"require": "./dist/data.js",
|
|
32
32
|
"types": "./dist/data.d.ts"
|
|
33
|
+
},
|
|
34
|
+
"./logging": {
|
|
35
|
+
"@arcanejs/source": "./src/logging.ts",
|
|
36
|
+
"import": "./dist/logging.mjs",
|
|
37
|
+
"require": "./dist/logging.js",
|
|
38
|
+
"types": "./dist/logging.d.ts"
|
|
33
39
|
}
|
|
34
40
|
},
|
|
35
41
|
"devDependencies": {
|
|
@@ -49,7 +55,8 @@
|
|
|
49
55
|
"lodash": "^4.17.21",
|
|
50
56
|
"react": "^18",
|
|
51
57
|
"react-reconciler": "0.28.0",
|
|
52
|
-
"@arcanejs/
|
|
58
|
+
"@arcanejs/protocol": "^0.2.0",
|
|
59
|
+
"@arcanejs/toolkit": "^0.3.0"
|
|
53
60
|
},
|
|
54
61
|
"peerDependencies": {
|
|
55
62
|
"zod": "^3.23.8"
|
package/dist/index.d.mts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import * as ld from '@arcanejs/toolkit';
|
|
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
|
-
import * as React from 'react';
|
|
12
|
-
import { Ref } from 'react';
|
|
13
|
-
|
|
14
|
-
type Child = JSX.Element | string | null | undefined | boolean;
|
|
15
|
-
type Children = Child | Child[];
|
|
16
|
-
interface LightDeskIntrinsicElements {
|
|
17
|
-
button: Props & {
|
|
18
|
-
children?: never;
|
|
19
|
-
onClick?: Events['click'];
|
|
20
|
-
ref?: Ref<Button$1>;
|
|
21
|
-
};
|
|
22
|
-
group: Props$1 & {
|
|
23
|
-
children?: Children;
|
|
24
|
-
onTitleChanged?: Events$1['title-changed'];
|
|
25
|
-
ref?: Ref<Group$1>;
|
|
26
|
-
};
|
|
27
|
-
'group-header': {
|
|
28
|
-
children?: Children;
|
|
29
|
-
ref?: Ref<GroupHeader$1>;
|
|
30
|
-
};
|
|
31
|
-
label: Props$2 & {
|
|
32
|
-
children?: never;
|
|
33
|
-
ref?: Ref<Label$1>;
|
|
34
|
-
};
|
|
35
|
-
rect: Props$3 & {
|
|
36
|
-
children?: never;
|
|
37
|
-
ref?: Ref<Rect$1>;
|
|
38
|
-
};
|
|
39
|
-
'slider-button': Props$4 & {
|
|
40
|
-
children?: never;
|
|
41
|
-
onChange?: Events$2['change'];
|
|
42
|
-
ref?: Ref<SliderButton$1>;
|
|
43
|
-
};
|
|
44
|
-
switch: Props$5 & {
|
|
45
|
-
children?: never;
|
|
46
|
-
onChange?: Events$3['change'];
|
|
47
|
-
ref?: Ref<Switch$1>;
|
|
48
|
-
};
|
|
49
|
-
tab: TabProps & {
|
|
50
|
-
children?: JSX.Element | string;
|
|
51
|
-
ref?: Ref<Tab$1>;
|
|
52
|
-
};
|
|
53
|
-
tabs: TabsProps & {
|
|
54
|
-
children?: JSX.Element | JSX.Element[];
|
|
55
|
-
ref?: Ref<Tabs$1>;
|
|
56
|
-
};
|
|
57
|
-
'text-input': Props$6 & {
|
|
58
|
-
children?: JSX.Element | JSX.Element[];
|
|
59
|
-
onChange?: Events$4['change'];
|
|
60
|
-
ref?: Ref<TextInput$1>;
|
|
61
|
-
};
|
|
62
|
-
timeline: Props$7 & {
|
|
63
|
-
children?: never;
|
|
64
|
-
ref?: Ref<Timeline$1>;
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
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']>;
|
|
80
|
-
|
|
81
|
-
declare const ToolkitRenderer: {
|
|
82
|
-
renderGroup: (component: JSX.Element, container: ld.Group) => void;
|
|
83
|
-
render: (component: JSX.Element, container: ld.Toolkit, rootGroupProps?: Props$1) => void;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
export { Button, Group, GroupHeader, Label, type LightDeskIntrinsicElements, Rect, SliderButton, Switch, Tab, Tabs, TextInput, Timeline, ToolkitRenderer };
|
package/dist/index.d.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import * as ld from '@arcanejs/toolkit';
|
|
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
|
-
import * as React from 'react';
|
|
12
|
-
import { Ref } from 'react';
|
|
13
|
-
|
|
14
|
-
type Child = JSX.Element | string | null | undefined | boolean;
|
|
15
|
-
type Children = Child | Child[];
|
|
16
|
-
interface LightDeskIntrinsicElements {
|
|
17
|
-
button: Props & {
|
|
18
|
-
children?: never;
|
|
19
|
-
onClick?: Events['click'];
|
|
20
|
-
ref?: Ref<Button$1>;
|
|
21
|
-
};
|
|
22
|
-
group: Props$1 & {
|
|
23
|
-
children?: Children;
|
|
24
|
-
onTitleChanged?: Events$1['title-changed'];
|
|
25
|
-
ref?: Ref<Group$1>;
|
|
26
|
-
};
|
|
27
|
-
'group-header': {
|
|
28
|
-
children?: Children;
|
|
29
|
-
ref?: Ref<GroupHeader$1>;
|
|
30
|
-
};
|
|
31
|
-
label: Props$2 & {
|
|
32
|
-
children?: never;
|
|
33
|
-
ref?: Ref<Label$1>;
|
|
34
|
-
};
|
|
35
|
-
rect: Props$3 & {
|
|
36
|
-
children?: never;
|
|
37
|
-
ref?: Ref<Rect$1>;
|
|
38
|
-
};
|
|
39
|
-
'slider-button': Props$4 & {
|
|
40
|
-
children?: never;
|
|
41
|
-
onChange?: Events$2['change'];
|
|
42
|
-
ref?: Ref<SliderButton$1>;
|
|
43
|
-
};
|
|
44
|
-
switch: Props$5 & {
|
|
45
|
-
children?: never;
|
|
46
|
-
onChange?: Events$3['change'];
|
|
47
|
-
ref?: Ref<Switch$1>;
|
|
48
|
-
};
|
|
49
|
-
tab: TabProps & {
|
|
50
|
-
children?: JSX.Element | string;
|
|
51
|
-
ref?: Ref<Tab$1>;
|
|
52
|
-
};
|
|
53
|
-
tabs: TabsProps & {
|
|
54
|
-
children?: JSX.Element | JSX.Element[];
|
|
55
|
-
ref?: Ref<Tabs$1>;
|
|
56
|
-
};
|
|
57
|
-
'text-input': Props$6 & {
|
|
58
|
-
children?: JSX.Element | JSX.Element[];
|
|
59
|
-
onChange?: Events$4['change'];
|
|
60
|
-
ref?: Ref<TextInput$1>;
|
|
61
|
-
};
|
|
62
|
-
timeline: Props$7 & {
|
|
63
|
-
children?: never;
|
|
64
|
-
ref?: Ref<Timeline$1>;
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
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']>;
|
|
80
|
-
|
|
81
|
-
declare const ToolkitRenderer: {
|
|
82
|
-
renderGroup: (component: JSX.Element, container: ld.Group) => void;
|
|
83
|
-
render: (component: JSX.Element, container: ld.Toolkit, rootGroupProps?: Props$1) => void;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
export { Button, Group, GroupHeader, Label, type LightDeskIntrinsicElements, Rect, SliderButton, Switch, Tab, Tabs, TextInput, Timeline, ToolkitRenderer };
|
package/dist/index.js
DELETED
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var src_exports = {};
|
|
32
|
-
__export(src_exports, {
|
|
33
|
-
Button: () => Button,
|
|
34
|
-
Group: () => Group,
|
|
35
|
-
GroupHeader: () => GroupHeader,
|
|
36
|
-
Label: () => Label,
|
|
37
|
-
Rect: () => Rect,
|
|
38
|
-
SliderButton: () => SliderButton,
|
|
39
|
-
Switch: () => Switch,
|
|
40
|
-
Tab: () => Tab,
|
|
41
|
-
Tabs: () => Tabs,
|
|
42
|
-
TextInput: () => TextInput,
|
|
43
|
-
Timeline: () => Timeline,
|
|
44
|
-
ToolkitRenderer: () => ToolkitRenderer
|
|
45
|
-
});
|
|
46
|
-
module.exports = __toCommonJS(src_exports);
|
|
47
|
-
var import_react_reconciler = __toESM(require("react-reconciler"));
|
|
48
|
-
var import_constants = require("react-reconciler/constants");
|
|
49
|
-
var ld = __toESM(require("@arcanejs/toolkit"));
|
|
50
|
-
var import_base = require("@arcanejs/toolkit/components/base");
|
|
51
|
-
|
|
52
|
-
// src/components.ts
|
|
53
|
-
var React = __toESM(require("react"));
|
|
54
|
-
var Button = React.forwardRef(
|
|
55
|
-
(props, ref) => React.createElement("button", { ...props, ref }, props.children)
|
|
56
|
-
);
|
|
57
|
-
var Group = React.forwardRef(
|
|
58
|
-
(props, ref) => React.createElement("group", { ...props, ref }, props.children)
|
|
59
|
-
);
|
|
60
|
-
var GroupHeader = React.forwardRef(
|
|
61
|
-
(props, ref) => React.createElement("group-header", { ...props, ref }, props.children)
|
|
62
|
-
);
|
|
63
|
-
var Label = React.forwardRef(
|
|
64
|
-
(props, ref) => React.createElement("label", { ...props, ref }, props.children)
|
|
65
|
-
);
|
|
66
|
-
var Rect = React.forwardRef(
|
|
67
|
-
(props, ref) => React.createElement("rect", { ...props, ref }, props.children)
|
|
68
|
-
);
|
|
69
|
-
var SliderButton = React.forwardRef(
|
|
70
|
-
(props, ref) => React.createElement("slider-button", { ...props, ref }, props.children)
|
|
71
|
-
);
|
|
72
|
-
var Switch = React.forwardRef(
|
|
73
|
-
(props, ref) => React.createElement("switch", { ...props, ref }, props.children)
|
|
74
|
-
);
|
|
75
|
-
var Tab = React.forwardRef(
|
|
76
|
-
(props, ref) => React.createElement("tab", { ...props, ref }, props.children)
|
|
77
|
-
);
|
|
78
|
-
var Tabs = React.forwardRef(
|
|
79
|
-
(props, ref) => React.createElement("tabs", { ...props, ref }, props.children)
|
|
80
|
-
);
|
|
81
|
-
var TextInput = React.forwardRef(
|
|
82
|
-
(props, ref) => React.createElement("text-input", { ...props, ref }, props.children)
|
|
83
|
-
);
|
|
84
|
-
var Timeline = React.forwardRef(
|
|
85
|
-
(props, ref) => React.createElement("timeline", { ...props, ref }, props.children)
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
// src/index.ts
|
|
89
|
-
var isType = (targetType, type, _props) => targetType === type;
|
|
90
|
-
var canSetProps = (instance) => instance instanceof import_base.Base;
|
|
91
|
-
var updateListener = (eventName, property, instance, prevProps, nextProps) => {
|
|
92
|
-
const prev = prevProps[property];
|
|
93
|
-
const next = nextProps[property];
|
|
94
|
-
if (prev !== next) {
|
|
95
|
-
prev && instance.removeListener(eventName, prev);
|
|
96
|
-
next && instance.addListener(eventName, next);
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
var updateListeners = (type, instance, prevProps, nextProps) => {
|
|
100
|
-
if (isType("button", type, prevProps) && isType("button", type, nextProps)) {
|
|
101
|
-
if (instance instanceof ld.Button) {
|
|
102
|
-
updateListener("click", "onClick", instance, prevProps, nextProps);
|
|
103
|
-
}
|
|
104
|
-
} else if (isType("group", type, prevProps) && isType("group", type, nextProps)) {
|
|
105
|
-
if (instance instanceof ld.Group) {
|
|
106
|
-
updateListener(
|
|
107
|
-
"title-changed",
|
|
108
|
-
"onTitleChanged",
|
|
109
|
-
instance,
|
|
110
|
-
prevProps,
|
|
111
|
-
nextProps
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
} else if (isType("slider-button", type, prevProps) && isType("slider-button", type, nextProps)) {
|
|
115
|
-
if (instance instanceof ld.SliderButton) {
|
|
116
|
-
updateListener("change", "onChange", instance, prevProps, nextProps);
|
|
117
|
-
}
|
|
118
|
-
} else if (isType("switch", type, prevProps) && isType("switch", type, nextProps)) {
|
|
119
|
-
if (instance instanceof ld.Switch) {
|
|
120
|
-
updateListener("change", "onChange", instance, prevProps, nextProps);
|
|
121
|
-
}
|
|
122
|
-
} else if (isType("text-input", type, prevProps) && isType("text-input", type, nextProps)) {
|
|
123
|
-
if (instance instanceof ld.TextInput) {
|
|
124
|
-
updateListener("change", "onChange", instance, prevProps, nextProps);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
var hostConfig = {
|
|
129
|
-
supportsMutation: true,
|
|
130
|
-
supportsPersistence: false,
|
|
131
|
-
noTimeout: -1,
|
|
132
|
-
isPrimaryRenderer: true,
|
|
133
|
-
supportsHydration: false,
|
|
134
|
-
afterActiveInstanceBlur: () => null,
|
|
135
|
-
appendChild: (parentInstance, child) => {
|
|
136
|
-
if (parentInstance instanceof import_base.BaseParent) {
|
|
137
|
-
parentInstance.appendChild(child);
|
|
138
|
-
} else {
|
|
139
|
-
throw new Error(`Unexpected Parent: ${parentInstance}`);
|
|
140
|
-
}
|
|
141
|
-
},
|
|
142
|
-
appendInitialChild: (parentInstance, child) => {
|
|
143
|
-
if (parentInstance instanceof import_base.BaseParent) {
|
|
144
|
-
parentInstance.appendChild(child);
|
|
145
|
-
} else {
|
|
146
|
-
throw new Error(`Unexpected Parent: ${parentInstance}`);
|
|
147
|
-
}
|
|
148
|
-
},
|
|
149
|
-
appendChildToContainer(container, child) {
|
|
150
|
-
container.appendChild(child);
|
|
151
|
-
},
|
|
152
|
-
beforeActiveInstanceBlur: () => null,
|
|
153
|
-
cancelTimeout: (id) => clearTimeout(id),
|
|
154
|
-
clearContainer: (container) => container.removeAllChildren(),
|
|
155
|
-
commitMount: () => {
|
|
156
|
-
throw new Error(`Unexpected call to commitMount()`);
|
|
157
|
-
},
|
|
158
|
-
commitUpdate(instance, updatePayload, type, prevProps, nextProps, _internalHandle) {
|
|
159
|
-
if (canSetProps(instance)) {
|
|
160
|
-
instance.setProps(updatePayload);
|
|
161
|
-
updateListeners(type, instance, prevProps, nextProps);
|
|
162
|
-
} else {
|
|
163
|
-
throw new Error(`Unexpected Instance: ${instance}`);
|
|
164
|
-
}
|
|
165
|
-
},
|
|
166
|
-
commitTextUpdate: (textInstance, _oldText, newText) => textInstance.setText(newText),
|
|
167
|
-
createInstance: (type, props) => {
|
|
168
|
-
let instance = null;
|
|
169
|
-
if (isType("button", type, props)) {
|
|
170
|
-
instance = new ld.Button(props);
|
|
171
|
-
} else if (isType("group", type, props)) {
|
|
172
|
-
instance = new ld.Group(props);
|
|
173
|
-
} else if (isType("group-header", type, props)) {
|
|
174
|
-
instance = new ld.GroupHeader(props);
|
|
175
|
-
} else if (isType("label", type, props)) {
|
|
176
|
-
instance = new ld.Label(props);
|
|
177
|
-
} else if (isType("rect", type, props)) {
|
|
178
|
-
instance = new ld.Rect(props);
|
|
179
|
-
} else if (isType("slider-button", type, props)) {
|
|
180
|
-
instance = new ld.SliderButton(props);
|
|
181
|
-
} else if (isType("switch", type, props)) {
|
|
182
|
-
instance = new ld.Switch(props);
|
|
183
|
-
} else if (isType("tab", type, props)) {
|
|
184
|
-
instance = new ld.Tab(props);
|
|
185
|
-
} else if (isType("tabs", type, props)) {
|
|
186
|
-
instance = new ld.Tabs(props);
|
|
187
|
-
} else if (isType("text-input", type, props)) {
|
|
188
|
-
instance = new ld.TextInput(props);
|
|
189
|
-
} else if (isType("timeline", type, props)) {
|
|
190
|
-
instance = new ld.Timeline(props);
|
|
191
|
-
}
|
|
192
|
-
if (instance) {
|
|
193
|
-
updateListeners(type, instance, {}, props);
|
|
194
|
-
return instance;
|
|
195
|
-
} else {
|
|
196
|
-
throw new Error(`Not implemented type: ${type}`);
|
|
197
|
-
}
|
|
198
|
-
},
|
|
199
|
-
createTextInstance: (text) => new ld.Label({ text }),
|
|
200
|
-
detachDeletedInstance: () => null,
|
|
201
|
-
getChildHostContext: (parentHostContext) => parentHostContext,
|
|
202
|
-
getCurrentEventPriority: () => import_constants.DefaultEventPriority,
|
|
203
|
-
getInstanceFromNode: () => {
|
|
204
|
-
throw new Error("Not yet implemented.");
|
|
205
|
-
},
|
|
206
|
-
getInstanceFromScope: () => {
|
|
207
|
-
throw new Error("Not yet implemented.");
|
|
208
|
-
},
|
|
209
|
-
getPublicInstance: (instance) => instance,
|
|
210
|
-
getRootHostContext: () => null,
|
|
211
|
-
insertBefore: (parentInstance, child, beforeChild) => {
|
|
212
|
-
if (parentInstance instanceof import_base.BaseParent) {
|
|
213
|
-
parentInstance.insertBefore(child, beforeChild);
|
|
214
|
-
} else {
|
|
215
|
-
throw new Error(`Unexpected Parent: ${parentInstance}`);
|
|
216
|
-
}
|
|
217
|
-
},
|
|
218
|
-
insertInContainerBefore: (container, child, beforeChild) => container.insertBefore(child, beforeChild),
|
|
219
|
-
finalizeInitialChildren: () => false,
|
|
220
|
-
prepareForCommit: () => null,
|
|
221
|
-
preparePortalMount: () => null,
|
|
222
|
-
prepareScopeUpdate: () => null,
|
|
223
|
-
prepareUpdate: (_instance, _type, _oldProps, newProps, _rootContainer, _hostContext) => {
|
|
224
|
-
const updates = {};
|
|
225
|
-
for (const [key, val] of Object.entries(newProps)) {
|
|
226
|
-
if (key !== "children") {
|
|
227
|
-
updates[key] = val;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
if (Object.keys(updates).length) {
|
|
231
|
-
return updates;
|
|
232
|
-
} else {
|
|
233
|
-
return null;
|
|
234
|
-
}
|
|
235
|
-
},
|
|
236
|
-
removeChild(parentInstance, child) {
|
|
237
|
-
if (parentInstance instanceof import_base.BaseParent) {
|
|
238
|
-
parentInstance.removeChild(child);
|
|
239
|
-
} else {
|
|
240
|
-
throw new Error(`Unexpected Parent: ${parentInstance}`);
|
|
241
|
-
}
|
|
242
|
-
},
|
|
243
|
-
removeChildFromContainer: (container, child) => container.removeChild(child),
|
|
244
|
-
resetAfterCommit: () => null,
|
|
245
|
-
resetTextContent: () => {
|
|
246
|
-
throw new Error(`Unexpected call to resetTextContent()`);
|
|
247
|
-
},
|
|
248
|
-
scheduleTimeout: (fn, delay) => setTimeout(fn, delay),
|
|
249
|
-
shouldSetTextContent: () => false,
|
|
250
|
-
// Not-implemented
|
|
251
|
-
hideInstance: () => {
|
|
252
|
-
console.log("Not-implemented: hideInstance");
|
|
253
|
-
},
|
|
254
|
-
hideTextInstance: () => {
|
|
255
|
-
console.log("Not-implemented: hideTextInstance");
|
|
256
|
-
},
|
|
257
|
-
unhideInstance: () => {
|
|
258
|
-
console.log("Not-implemented: unhideInstance");
|
|
259
|
-
},
|
|
260
|
-
unhideTextInstance: () => {
|
|
261
|
-
console.log("Not-implemented: unhideTextInstance");
|
|
262
|
-
}
|
|
263
|
-
};
|
|
264
|
-
var reconciler = (0, import_react_reconciler.default)(hostConfig);
|
|
265
|
-
var ToolkitRenderer = {
|
|
266
|
-
renderGroup: (component, container) => {
|
|
267
|
-
const root = reconciler.createContainer(container, 0, false, null);
|
|
268
|
-
reconciler.updateContainer(component, root, null);
|
|
269
|
-
},
|
|
270
|
-
render: (component, container, rootGroupProps) => {
|
|
271
|
-
const group = new ld.Group(rootGroupProps);
|
|
272
|
-
container.setRoot(group);
|
|
273
|
-
ToolkitRenderer.renderGroup(component, group);
|
|
274
|
-
}
|
|
275
|
-
};
|
|
276
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
277
|
-
0 && (module.exports = {
|
|
278
|
-
Button,
|
|
279
|
-
Group,
|
|
280
|
-
GroupHeader,
|
|
281
|
-
Label,
|
|
282
|
-
Rect,
|
|
283
|
-
SliderButton,
|
|
284
|
-
Switch,
|
|
285
|
-
Tab,
|
|
286
|
-
Tabs,
|
|
287
|
-
TextInput,
|
|
288
|
-
Timeline,
|
|
289
|
-
ToolkitRenderer
|
|
290
|
-
});
|
package/dist/index.mjs
DELETED
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
|
-
import Reconciler from "react-reconciler";
|
|
3
|
-
import { DefaultEventPriority } from "react-reconciler/constants";
|
|
4
|
-
import * as ld from "@arcanejs/toolkit";
|
|
5
|
-
import { Base, BaseParent } from "@arcanejs/toolkit/components/base";
|
|
6
|
-
|
|
7
|
-
// src/components.ts
|
|
8
|
-
import * as React from "react";
|
|
9
|
-
var Button = React.forwardRef(
|
|
10
|
-
(props, ref) => React.createElement("button", { ...props, ref }, props.children)
|
|
11
|
-
);
|
|
12
|
-
var Group = React.forwardRef(
|
|
13
|
-
(props, ref) => React.createElement("group", { ...props, ref }, props.children)
|
|
14
|
-
);
|
|
15
|
-
var GroupHeader = React.forwardRef(
|
|
16
|
-
(props, ref) => React.createElement("group-header", { ...props, ref }, props.children)
|
|
17
|
-
);
|
|
18
|
-
var Label = React.forwardRef(
|
|
19
|
-
(props, ref) => React.createElement("label", { ...props, ref }, props.children)
|
|
20
|
-
);
|
|
21
|
-
var Rect = React.forwardRef(
|
|
22
|
-
(props, ref) => React.createElement("rect", { ...props, ref }, props.children)
|
|
23
|
-
);
|
|
24
|
-
var SliderButton = React.forwardRef(
|
|
25
|
-
(props, ref) => React.createElement("slider-button", { ...props, ref }, props.children)
|
|
26
|
-
);
|
|
27
|
-
var Switch = React.forwardRef(
|
|
28
|
-
(props, ref) => React.createElement("switch", { ...props, ref }, props.children)
|
|
29
|
-
);
|
|
30
|
-
var Tab = React.forwardRef(
|
|
31
|
-
(props, ref) => React.createElement("tab", { ...props, ref }, props.children)
|
|
32
|
-
);
|
|
33
|
-
var Tabs = React.forwardRef(
|
|
34
|
-
(props, ref) => React.createElement("tabs", { ...props, ref }, props.children)
|
|
35
|
-
);
|
|
36
|
-
var TextInput = React.forwardRef(
|
|
37
|
-
(props, ref) => React.createElement("text-input", { ...props, ref }, props.children)
|
|
38
|
-
);
|
|
39
|
-
var Timeline = React.forwardRef(
|
|
40
|
-
(props, ref) => React.createElement("timeline", { ...props, ref }, props.children)
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
// src/index.ts
|
|
44
|
-
var isType = (targetType, type, _props) => targetType === type;
|
|
45
|
-
var canSetProps = (instance) => instance instanceof Base;
|
|
46
|
-
var updateListener = (eventName, property, instance, prevProps, nextProps) => {
|
|
47
|
-
const prev = prevProps[property];
|
|
48
|
-
const next = nextProps[property];
|
|
49
|
-
if (prev !== next) {
|
|
50
|
-
prev && instance.removeListener(eventName, prev);
|
|
51
|
-
next && instance.addListener(eventName, next);
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
var updateListeners = (type, instance, prevProps, nextProps) => {
|
|
55
|
-
if (isType("button", type, prevProps) && isType("button", type, nextProps)) {
|
|
56
|
-
if (instance instanceof ld.Button) {
|
|
57
|
-
updateListener("click", "onClick", instance, prevProps, nextProps);
|
|
58
|
-
}
|
|
59
|
-
} else if (isType("group", type, prevProps) && isType("group", type, nextProps)) {
|
|
60
|
-
if (instance instanceof ld.Group) {
|
|
61
|
-
updateListener(
|
|
62
|
-
"title-changed",
|
|
63
|
-
"onTitleChanged",
|
|
64
|
-
instance,
|
|
65
|
-
prevProps,
|
|
66
|
-
nextProps
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
} else if (isType("slider-button", type, prevProps) && isType("slider-button", type, nextProps)) {
|
|
70
|
-
if (instance instanceof ld.SliderButton) {
|
|
71
|
-
updateListener("change", "onChange", instance, prevProps, nextProps);
|
|
72
|
-
}
|
|
73
|
-
} else if (isType("switch", type, prevProps) && isType("switch", type, nextProps)) {
|
|
74
|
-
if (instance instanceof ld.Switch) {
|
|
75
|
-
updateListener("change", "onChange", instance, prevProps, nextProps);
|
|
76
|
-
}
|
|
77
|
-
} else if (isType("text-input", type, prevProps) && isType("text-input", type, nextProps)) {
|
|
78
|
-
if (instance instanceof ld.TextInput) {
|
|
79
|
-
updateListener("change", "onChange", instance, prevProps, nextProps);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
var hostConfig = {
|
|
84
|
-
supportsMutation: true,
|
|
85
|
-
supportsPersistence: false,
|
|
86
|
-
noTimeout: -1,
|
|
87
|
-
isPrimaryRenderer: true,
|
|
88
|
-
supportsHydration: false,
|
|
89
|
-
afterActiveInstanceBlur: () => null,
|
|
90
|
-
appendChild: (parentInstance, child) => {
|
|
91
|
-
if (parentInstance instanceof BaseParent) {
|
|
92
|
-
parentInstance.appendChild(child);
|
|
93
|
-
} else {
|
|
94
|
-
throw new Error(`Unexpected Parent: ${parentInstance}`);
|
|
95
|
-
}
|
|
96
|
-
},
|
|
97
|
-
appendInitialChild: (parentInstance, child) => {
|
|
98
|
-
if (parentInstance instanceof BaseParent) {
|
|
99
|
-
parentInstance.appendChild(child);
|
|
100
|
-
} else {
|
|
101
|
-
throw new Error(`Unexpected Parent: ${parentInstance}`);
|
|
102
|
-
}
|
|
103
|
-
},
|
|
104
|
-
appendChildToContainer(container, child) {
|
|
105
|
-
container.appendChild(child);
|
|
106
|
-
},
|
|
107
|
-
beforeActiveInstanceBlur: () => null,
|
|
108
|
-
cancelTimeout: (id) => clearTimeout(id),
|
|
109
|
-
clearContainer: (container) => container.removeAllChildren(),
|
|
110
|
-
commitMount: () => {
|
|
111
|
-
throw new Error(`Unexpected call to commitMount()`);
|
|
112
|
-
},
|
|
113
|
-
commitUpdate(instance, updatePayload, type, prevProps, nextProps, _internalHandle) {
|
|
114
|
-
if (canSetProps(instance)) {
|
|
115
|
-
instance.setProps(updatePayload);
|
|
116
|
-
updateListeners(type, instance, prevProps, nextProps);
|
|
117
|
-
} else {
|
|
118
|
-
throw new Error(`Unexpected Instance: ${instance}`);
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
commitTextUpdate: (textInstance, _oldText, newText) => textInstance.setText(newText),
|
|
122
|
-
createInstance: (type, props) => {
|
|
123
|
-
let instance = null;
|
|
124
|
-
if (isType("button", type, props)) {
|
|
125
|
-
instance = new ld.Button(props);
|
|
126
|
-
} else if (isType("group", type, props)) {
|
|
127
|
-
instance = new ld.Group(props);
|
|
128
|
-
} else if (isType("group-header", type, props)) {
|
|
129
|
-
instance = new ld.GroupHeader(props);
|
|
130
|
-
} else if (isType("label", type, props)) {
|
|
131
|
-
instance = new ld.Label(props);
|
|
132
|
-
} else if (isType("rect", type, props)) {
|
|
133
|
-
instance = new ld.Rect(props);
|
|
134
|
-
} else if (isType("slider-button", type, props)) {
|
|
135
|
-
instance = new ld.SliderButton(props);
|
|
136
|
-
} else if (isType("switch", type, props)) {
|
|
137
|
-
instance = new ld.Switch(props);
|
|
138
|
-
} else if (isType("tab", type, props)) {
|
|
139
|
-
instance = new ld.Tab(props);
|
|
140
|
-
} else if (isType("tabs", type, props)) {
|
|
141
|
-
instance = new ld.Tabs(props);
|
|
142
|
-
} else if (isType("text-input", type, props)) {
|
|
143
|
-
instance = new ld.TextInput(props);
|
|
144
|
-
} else if (isType("timeline", type, props)) {
|
|
145
|
-
instance = new ld.Timeline(props);
|
|
146
|
-
}
|
|
147
|
-
if (instance) {
|
|
148
|
-
updateListeners(type, instance, {}, props);
|
|
149
|
-
return instance;
|
|
150
|
-
} else {
|
|
151
|
-
throw new Error(`Not implemented type: ${type}`);
|
|
152
|
-
}
|
|
153
|
-
},
|
|
154
|
-
createTextInstance: (text) => new ld.Label({ text }),
|
|
155
|
-
detachDeletedInstance: () => null,
|
|
156
|
-
getChildHostContext: (parentHostContext) => parentHostContext,
|
|
157
|
-
getCurrentEventPriority: () => DefaultEventPriority,
|
|
158
|
-
getInstanceFromNode: () => {
|
|
159
|
-
throw new Error("Not yet implemented.");
|
|
160
|
-
},
|
|
161
|
-
getInstanceFromScope: () => {
|
|
162
|
-
throw new Error("Not yet implemented.");
|
|
163
|
-
},
|
|
164
|
-
getPublicInstance: (instance) => instance,
|
|
165
|
-
getRootHostContext: () => null,
|
|
166
|
-
insertBefore: (parentInstance, child, beforeChild) => {
|
|
167
|
-
if (parentInstance instanceof BaseParent) {
|
|
168
|
-
parentInstance.insertBefore(child, beforeChild);
|
|
169
|
-
} else {
|
|
170
|
-
throw new Error(`Unexpected Parent: ${parentInstance}`);
|
|
171
|
-
}
|
|
172
|
-
},
|
|
173
|
-
insertInContainerBefore: (container, child, beforeChild) => container.insertBefore(child, beforeChild),
|
|
174
|
-
finalizeInitialChildren: () => false,
|
|
175
|
-
prepareForCommit: () => null,
|
|
176
|
-
preparePortalMount: () => null,
|
|
177
|
-
prepareScopeUpdate: () => null,
|
|
178
|
-
prepareUpdate: (_instance, _type, _oldProps, newProps, _rootContainer, _hostContext) => {
|
|
179
|
-
const updates = {};
|
|
180
|
-
for (const [key, val] of Object.entries(newProps)) {
|
|
181
|
-
if (key !== "children") {
|
|
182
|
-
updates[key] = val;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
if (Object.keys(updates).length) {
|
|
186
|
-
return updates;
|
|
187
|
-
} else {
|
|
188
|
-
return null;
|
|
189
|
-
}
|
|
190
|
-
},
|
|
191
|
-
removeChild(parentInstance, child) {
|
|
192
|
-
if (parentInstance instanceof BaseParent) {
|
|
193
|
-
parentInstance.removeChild(child);
|
|
194
|
-
} else {
|
|
195
|
-
throw new Error(`Unexpected Parent: ${parentInstance}`);
|
|
196
|
-
}
|
|
197
|
-
},
|
|
198
|
-
removeChildFromContainer: (container, child) => container.removeChild(child),
|
|
199
|
-
resetAfterCommit: () => null,
|
|
200
|
-
resetTextContent: () => {
|
|
201
|
-
throw new Error(`Unexpected call to resetTextContent()`);
|
|
202
|
-
},
|
|
203
|
-
scheduleTimeout: (fn, delay) => setTimeout(fn, delay),
|
|
204
|
-
shouldSetTextContent: () => false,
|
|
205
|
-
// Not-implemented
|
|
206
|
-
hideInstance: () => {
|
|
207
|
-
console.log("Not-implemented: hideInstance");
|
|
208
|
-
},
|
|
209
|
-
hideTextInstance: () => {
|
|
210
|
-
console.log("Not-implemented: hideTextInstance");
|
|
211
|
-
},
|
|
212
|
-
unhideInstance: () => {
|
|
213
|
-
console.log("Not-implemented: unhideInstance");
|
|
214
|
-
},
|
|
215
|
-
unhideTextInstance: () => {
|
|
216
|
-
console.log("Not-implemented: unhideTextInstance");
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
var reconciler = Reconciler(hostConfig);
|
|
220
|
-
var ToolkitRenderer = {
|
|
221
|
-
renderGroup: (component, container) => {
|
|
222
|
-
const root = reconciler.createContainer(container, 0, false, null);
|
|
223
|
-
reconciler.updateContainer(component, root, null);
|
|
224
|
-
},
|
|
225
|
-
render: (component, container, rootGroupProps) => {
|
|
226
|
-
const group = new ld.Group(rootGroupProps);
|
|
227
|
-
container.setRoot(group);
|
|
228
|
-
ToolkitRenderer.renderGroup(component, group);
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
export {
|
|
232
|
-
Button,
|
|
233
|
-
Group,
|
|
234
|
-
GroupHeader,
|
|
235
|
-
Label,
|
|
236
|
-
Rect,
|
|
237
|
-
SliderButton,
|
|
238
|
-
Switch,
|
|
239
|
-
Tab,
|
|
240
|
-
Tabs,
|
|
241
|
-
TextInput,
|
|
242
|
-
Timeline,
|
|
243
|
-
ToolkitRenderer
|
|
244
|
-
};
|