@arcanejs/toolkit 0.2.1 → 0.2.2

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.
@@ -1,189 +1,11 @@
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);
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
19
2
 
20
- // src/backend/components/base.ts
21
- var base_exports = {};
22
- __export(base_exports, {
23
- Base: () => Base,
24
- BaseParent: () => BaseParent,
25
- EventEmitter: () => EventEmitter
26
- });
27
- module.exports = __toCommonJS(base_exports);
28
- var Base = class {
29
- /** @hidden */
30
- parent = null;
31
- /** @hidden */
32
- defaultProps;
33
- /** @hidden */
34
- _props;
35
- constructor(defaultProps, props) {
36
- this.defaultProps = defaultProps;
37
- this._props = Object.freeze({
38
- ...defaultProps,
39
- ...props
40
- });
41
- }
42
- get props() {
43
- return this._props;
44
- }
45
- set props(props) {
46
- this.setProps(props);
47
- }
48
- setProps = (props) => {
49
- this._props = Object.freeze({
50
- ...this.defaultProps,
51
- ...props
52
- });
53
- this.updateTree();
54
- };
55
- updateProps = (updates) => {
56
- this._props = Object.freeze({
57
- ...this._props,
58
- ...updates
59
- });
60
- this.updateTree();
61
- };
62
- /** @hidden */
63
- setParent(parent) {
64
- if (this.parent && this.parent !== parent) {
65
- this.parent.removeChild(this);
66
- }
67
- this.parent = parent;
68
- }
69
- /** @hidden */
70
- updateTree() {
71
- if (this.parent) this.parent.updateTree();
72
- }
73
- /** @hidden */
74
- handleMessage(message) {
75
- console.log("Component Received Message:", message);
76
- }
77
- routeMessage(_idMap, _message) {
78
- }
79
- };
80
- var BaseParent = class extends Base {
81
- /** @hidden */
82
- children = [];
83
- appendChildren = (...children) => {
84
- for (const c of children) {
85
- const newChildren = [...this.children.filter((ch) => ch !== c), c];
86
- this.validateChildren(newChildren);
87
- this.children = Object.freeze(newChildren);
88
- c.setParent(this);
89
- }
90
- this.updateTree();
91
- return children;
92
- };
93
- appendChild = (child) => {
94
- this.appendChildren(child);
95
- return child;
96
- };
97
- removeChild = (component) => {
98
- const match = this.children.findIndex((c) => c === component);
99
- if (match >= 0) {
100
- const removingChild = this.children[match];
101
- const newChildren = [
102
- ...this.children.slice(0, match),
103
- ...this.children.slice(match + 1)
104
- ];
105
- this.validateChildren(newChildren);
106
- this.children = Object.freeze(newChildren);
107
- removingChild?.setParent(null);
108
- this.updateTree();
109
- }
110
- };
111
- removeAllChildren = () => {
112
- this.children.map((c) => c.setParent(null));
113
- this.children = Object.freeze([]);
114
- this.updateTree();
115
- };
116
- /**
117
- * Return all children components that messages need to be routed to
118
- */
119
- getChildren = () => this.children;
120
- /**
121
- * TODO: we can do this better, right now it broadcasts the message to all
122
- * components of the tree
123
- *
124
- * @hidden
125
- */
126
- routeMessage(idMap, message) {
127
- if (idMap.getId(this) === message.componentKey) {
128
- this.handleMessage(message);
129
- } else {
130
- for (const c of this.children) {
131
- if (idMap.getId(c) === message.componentKey) {
132
- c.handleMessage(message);
133
- } else {
134
- c.routeMessage(idMap, message);
135
- }
136
- }
137
- }
138
- }
139
- insertBefore(child, beforeChild) {
140
- const filteredChildren = this.children.filter((c) => c !== child);
141
- let match = filteredChildren.findIndex((c) => c === beforeChild);
142
- console.log("match", match);
143
- if (match === -1) {
144
- match = filteredChildren.length;
145
- }
146
- const newChildren = [
147
- ...filteredChildren.slice(0, match),
148
- child,
149
- ...filteredChildren.slice(match)
150
- ];
151
- this.validateChildren(newChildren);
152
- this.children = Object.freeze(newChildren);
153
- child.setParent(this);
154
- this.updateTree();
155
- }
156
- };
157
- var EventEmitter = class {
158
- listeners = /* @__PURE__ */ new Map();
159
- addListener = (type, listener) => {
160
- let set = this.listeners.get(type);
161
- if (!set) {
162
- set = /* @__PURE__ */ new Set();
163
- this.listeners.set(type, set);
164
- }
165
- set.add(listener);
166
- };
167
- removeListener = (type, listener) => {
168
- this.listeners.get(type)?.delete(listener);
169
- };
170
- emit = (type, ...args) => {
171
- return Promise.all(
172
- [...this.listeners.get(type) || []].map(
173
- (l) => new Promise((resolve, reject) => {
174
- try {
175
- resolve(l(...args));
176
- } catch (e) {
177
- reject(e);
178
- }
179
- })
180
- )
181
- );
182
- };
183
- };
184
- // Annotate the CommonJS export names for ESM import in node:
185
- 0 && (module.exports = {
186
- Base,
187
- BaseParent,
188
- EventEmitter
189
- });
3
+
4
+
5
+ var _chunkUBWCVW2Ujs = require('../../chunk-UBWCVW2U.js');
6
+ require('../../chunk-3RG5ZIWI.js');
7
+
8
+
9
+
10
+
11
+ exports.Base = _chunkUBWCVW2Ujs.Base; exports.BaseParent = _chunkUBWCVW2Ujs.BaseParent; exports.EventEmitter = _chunkUBWCVW2Ujs.EventEmitter;
@@ -1,168 +1,8 @@
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);
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
19
2
 
20
- // src/backend/components/button.ts
21
- var button_exports = {};
22
- __export(button_exports, {
23
- Button: () => Button
24
- });
25
- module.exports = __toCommonJS(button_exports);
3
+ var _chunkKVJU3EADjs = require('../../chunk-KVJU3EAD.js');
4
+ require('../../chunk-UBWCVW2U.js');
5
+ require('../../chunk-3RG5ZIWI.js');
26
6
 
27
- // src/backend/components/base.ts
28
- var Base = class {
29
- /** @hidden */
30
- parent = null;
31
- /** @hidden */
32
- defaultProps;
33
- /** @hidden */
34
- _props;
35
- constructor(defaultProps, props) {
36
- this.defaultProps = defaultProps;
37
- this._props = Object.freeze({
38
- ...defaultProps,
39
- ...props
40
- });
41
- }
42
- get props() {
43
- return this._props;
44
- }
45
- set props(props) {
46
- this.setProps(props);
47
- }
48
- setProps = (props) => {
49
- this._props = Object.freeze({
50
- ...this.defaultProps,
51
- ...props
52
- });
53
- this.updateTree();
54
- };
55
- updateProps = (updates) => {
56
- this._props = Object.freeze({
57
- ...this._props,
58
- ...updates
59
- });
60
- this.updateTree();
61
- };
62
- /** @hidden */
63
- setParent(parent) {
64
- if (this.parent && this.parent !== parent) {
65
- this.parent.removeChild(this);
66
- }
67
- this.parent = parent;
68
- }
69
- /** @hidden */
70
- updateTree() {
71
- if (this.parent) this.parent.updateTree();
72
- }
73
- /** @hidden */
74
- handleMessage(message) {
75
- console.log("Component Received Message:", message);
76
- }
77
- routeMessage(_idMap, _message) {
78
- }
79
- };
80
- var EventEmitter = class {
81
- listeners = /* @__PURE__ */ new Map();
82
- addListener = (type, listener) => {
83
- let set = this.listeners.get(type);
84
- if (!set) {
85
- set = /* @__PURE__ */ new Set();
86
- this.listeners.set(type, set);
87
- }
88
- set.add(listener);
89
- };
90
- removeListener = (type, listener) => {
91
- this.listeners.get(type)?.delete(listener);
92
- };
93
- emit = (type, ...args) => {
94
- return Promise.all(
95
- [...this.listeners.get(type) || []].map(
96
- (l) => new Promise((resolve, reject) => {
97
- try {
98
- resolve(l(...args));
99
- } catch (e) {
100
- reject(e);
101
- }
102
- })
103
- )
104
- );
105
- };
106
- };
107
7
 
108
- // src/backend/components/button.ts
109
- var DEFAULT_PROPS = {
110
- text: null,
111
- icon: null,
112
- mode: "normal",
113
- error: null
114
- };
115
- var Button = class extends Base {
116
- /** @hidden */
117
- events = new EventEmitter();
118
- constructor(props) {
119
- super(DEFAULT_PROPS, props);
120
- }
121
- addListener = this.events.addListener;
122
- removeListener = this.events.removeListener;
123
- setText = (text) => {
124
- this.updateProps({ text });
125
- return this;
126
- };
127
- setIcon = (icon) => {
128
- this.updateProps({ icon: icon ?? null });
129
- return this;
130
- };
131
- setMode = (mode) => {
132
- this.updateProps({
133
- mode,
134
- error: null
135
- });
136
- return this;
137
- };
138
- /** @hidden */
139
- getProtoInfo = (idMap) => {
140
- return {
141
- component: "button",
142
- key: idMap.getId(this),
143
- text: this.props.text || "",
144
- state: this.props.error ? { state: "error", error: this.props.error } : { state: this.props.mode },
145
- icon: this.props.icon ?? void 0
146
- };
147
- };
148
- /** @hidden */
149
- handleMessage = (message) => {
150
- if (message.component === "button") {
151
- this.events.emit("click").then(() => {
152
- if (this.props.error) {
153
- this.updateProps({
154
- error: null
155
- });
156
- }
157
- }).catch((e) => {
158
- this.updateProps({
159
- error: `${e}`
160
- });
161
- });
162
- }
163
- };
164
- };
165
- // Annotate the CommonJS export names for ESM import in node:
166
- 0 && (module.exports = {
167
- Button
168
- });
8
+ exports.Button = _chunkKVJU3EADjs.Button;
@@ -1,284 +1,10 @@
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);
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
19
2
 
20
- // src/backend/components/group.ts
21
- var group_exports = {};
22
- __export(group_exports, {
23
- Group: () => Group,
24
- GroupHeader: () => GroupHeader
25
- });
26
- module.exports = __toCommonJS(group_exports);
27
3
 
28
- // src/backend/components/base.ts
29
- var Base = class {
30
- /** @hidden */
31
- parent = null;
32
- /** @hidden */
33
- defaultProps;
34
- /** @hidden */
35
- _props;
36
- constructor(defaultProps, props) {
37
- this.defaultProps = defaultProps;
38
- this._props = Object.freeze({
39
- ...defaultProps,
40
- ...props
41
- });
42
- }
43
- get props() {
44
- return this._props;
45
- }
46
- set props(props) {
47
- this.setProps(props);
48
- }
49
- setProps = (props) => {
50
- this._props = Object.freeze({
51
- ...this.defaultProps,
52
- ...props
53
- });
54
- this.updateTree();
55
- };
56
- updateProps = (updates) => {
57
- this._props = Object.freeze({
58
- ...this._props,
59
- ...updates
60
- });
61
- this.updateTree();
62
- };
63
- /** @hidden */
64
- setParent(parent) {
65
- if (this.parent && this.parent !== parent) {
66
- this.parent.removeChild(this);
67
- }
68
- this.parent = parent;
69
- }
70
- /** @hidden */
71
- updateTree() {
72
- if (this.parent) this.parent.updateTree();
73
- }
74
- /** @hidden */
75
- handleMessage(message) {
76
- console.log("Component Received Message:", message);
77
- }
78
- routeMessage(_idMap, _message) {
79
- }
80
- };
81
- var BaseParent = class extends Base {
82
- /** @hidden */
83
- children = [];
84
- appendChildren = (...children) => {
85
- for (const c of children) {
86
- const newChildren = [...this.children.filter((ch) => ch !== c), c];
87
- this.validateChildren(newChildren);
88
- this.children = Object.freeze(newChildren);
89
- c.setParent(this);
90
- }
91
- this.updateTree();
92
- return children;
93
- };
94
- appendChild = (child) => {
95
- this.appendChildren(child);
96
- return child;
97
- };
98
- removeChild = (component) => {
99
- const match = this.children.findIndex((c) => c === component);
100
- if (match >= 0) {
101
- const removingChild = this.children[match];
102
- const newChildren = [
103
- ...this.children.slice(0, match),
104
- ...this.children.slice(match + 1)
105
- ];
106
- this.validateChildren(newChildren);
107
- this.children = Object.freeze(newChildren);
108
- removingChild?.setParent(null);
109
- this.updateTree();
110
- }
111
- };
112
- removeAllChildren = () => {
113
- this.children.map((c) => c.setParent(null));
114
- this.children = Object.freeze([]);
115
- this.updateTree();
116
- };
117
- /**
118
- * Return all children components that messages need to be routed to
119
- */
120
- getChildren = () => this.children;
121
- /**
122
- * TODO: we can do this better, right now it broadcasts the message to all
123
- * components of the tree
124
- *
125
- * @hidden
126
- */
127
- routeMessage(idMap, message) {
128
- if (idMap.getId(this) === message.componentKey) {
129
- this.handleMessage(message);
130
- } else {
131
- for (const c of this.children) {
132
- if (idMap.getId(c) === message.componentKey) {
133
- c.handleMessage(message);
134
- } else {
135
- c.routeMessage(idMap, message);
136
- }
137
- }
138
- }
139
- }
140
- insertBefore(child, beforeChild) {
141
- const filteredChildren = this.children.filter((c) => c !== child);
142
- let match = filteredChildren.findIndex((c) => c === beforeChild);
143
- console.log("match", match);
144
- if (match === -1) {
145
- match = filteredChildren.length;
146
- }
147
- const newChildren = [
148
- ...filteredChildren.slice(0, match),
149
- child,
150
- ...filteredChildren.slice(match)
151
- ];
152
- this.validateChildren(newChildren);
153
- this.children = Object.freeze(newChildren);
154
- child.setParent(this);
155
- this.updateTree();
156
- }
157
- };
158
- var EventEmitter = class {
159
- listeners = /* @__PURE__ */ new Map();
160
- addListener = (type, listener) => {
161
- let set = this.listeners.get(type);
162
- if (!set) {
163
- set = /* @__PURE__ */ new Set();
164
- this.listeners.set(type, set);
165
- }
166
- set.add(listener);
167
- };
168
- removeListener = (type, listener) => {
169
- this.listeners.get(type)?.delete(listener);
170
- };
171
- emit = (type, ...args) => {
172
- return Promise.all(
173
- [...this.listeners.get(type) || []].map(
174
- (l) => new Promise((resolve, reject) => {
175
- try {
176
- resolve(l(...args));
177
- } catch (e) {
178
- reject(e);
179
- }
180
- })
181
- )
182
- );
183
- };
184
- };
4
+ var _chunkK24YPCR5js = require('../../chunk-K24YPCR5.js');
5
+ require('../../chunk-UBWCVW2U.js');
6
+ require('../../chunk-3RG5ZIWI.js');
185
7
 
186
- // src/backend/components/group.ts
187
- var GROUP_DEFAULT_STYLE = {
188
- direction: "horizontal"
189
- };
190
- var DEFAULT_PROPS = {
191
- ...GROUP_DEFAULT_STYLE,
192
- title: null,
193
- labels: null
194
- };
195
- var GroupHeader = class extends BaseParent {
196
- validateChildren = () => {
197
- };
198
- /** @hidden */
199
- getProtoInfo = (idMap) => ({
200
- component: "group-header",
201
- key: idMap.getId(this),
202
- children: this.getChildren().map((c) => c.getProtoInfo(idMap))
203
- });
204
- };
205
- var Group = class extends BaseParent {
206
- /** @hidden */
207
- events = new EventEmitter();
208
- constructor(props) {
209
- super(DEFAULT_PROPS, props);
210
- }
211
- addListener = this.events.addListener;
212
- removeListener = this.events.removeListener;
213
- validateChildren = () => {
214
- };
215
- setOptions = (options) => {
216
- this.updateProps(options);
217
- };
218
- setTitle = (title) => {
219
- this.updateProps({ title });
220
- };
221
- addLabel = (label) => {
222
- this.updateProps({ labels: [...this.props.labels || [], label] });
223
- };
224
- setLabels = (labels) => {
225
- this.updateProps({ labels });
226
- };
227
- addHeaderChild = (child) => {
228
- const header = new GroupHeader({});
229
- header.appendChild(child);
230
- this.appendChild(header);
231
- return child;
232
- };
233
- removeHeaderChild = (child) => {
234
- for (const c of this.getChildren()) {
235
- if (c instanceof GroupHeader) {
236
- c.removeChild(child);
237
- }
238
- }
239
- };
240
- removeAllHeaderChildren = () => {
241
- for (const child of this.getChildren()) {
242
- if (child instanceof GroupHeader) {
243
- child.removeAllChildren();
244
- }
245
- }
246
- };
247
- /** @hidden */
248
- getProtoInfo = (idMap) => {
249
- const children = [];
250
- const headers = [];
251
- for (const c of this.getChildren()) {
252
- const childProto = c.getProtoInfo(idMap);
253
- if (childProto.component === "group-header") {
254
- headers.push(childProto);
255
- } else {
256
- children.push(childProto);
257
- }
258
- }
259
- return {
260
- component: "group",
261
- key: idMap.getId(this),
262
- title: this.props.title ?? void 0,
263
- direction: this.props.direction,
264
- border: this.props.border,
265
- wrap: this.props.wrap,
266
- children,
267
- headers: headers.length > 0 ? headers : void 0,
268
- labels: this.props.labels ?? void 0,
269
- editableTitle: this.props.editableTitle || false,
270
- defaultCollapsibleState: this.props.defaultCollapsibleState
271
- };
272
- };
273
- /** @hidden */
274
- handleMessage = (message) => {
275
- if (message.component === "group") {
276
- this.events.emit("title-changed", message.title);
277
- }
278
- };
279
- };
280
- // Annotate the CommonJS export names for ESM import in node:
281
- 0 && (module.exports = {
282
- Group,
283
- GroupHeader
284
- });
8
+
9
+
10
+ exports.Group = _chunkK24YPCR5js.Group; exports.GroupHeader = _chunkK24YPCR5js.GroupHeader;