atom.io 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.
Files changed (54) hide show
  1. package/README.md +11 -3
  2. package/dist/index.d.ts +83 -30
  3. package/dist/index.js +427 -230
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +427 -230
  6. package/dist/index.mjs.map +1 -1
  7. package/package.json +15 -5
  8. package/react/dist/index.d.ts +12 -17
  9. package/react/dist/index.js +25 -34
  10. package/react/dist/index.js.map +1 -1
  11. package/react/dist/index.mjs +21 -34
  12. package/react/dist/index.mjs.map +1 -1
  13. package/react-devtools/dist/index.css +26 -0
  14. package/react-devtools/dist/index.css.map +1 -0
  15. package/react-devtools/dist/index.d.ts +15 -0
  16. package/react-devtools/dist/index.js +1579 -0
  17. package/react-devtools/dist/index.js.map +1 -0
  18. package/react-devtools/dist/index.mjs +1551 -0
  19. package/react-devtools/dist/index.mjs.map +1 -0
  20. package/react-devtools/package.json +15 -0
  21. package/src/index.ts +3 -3
  22. package/src/internal/atom-internal.ts +10 -5
  23. package/src/internal/families-internal.ts +4 -4
  24. package/src/internal/get.ts +8 -8
  25. package/src/internal/index.ts +2 -0
  26. package/src/internal/meta/attach-meta.ts +17 -0
  27. package/src/internal/meta/index.ts +4 -0
  28. package/src/internal/meta/meta-state.ts +135 -0
  29. package/src/internal/meta/meta-timelines.ts +1 -0
  30. package/src/internal/meta/meta-transactions.ts +1 -0
  31. package/src/internal/operation.ts +0 -1
  32. package/src/internal/selector-internal.ts +34 -13
  33. package/src/internal/store.ts +35 -5
  34. package/src/internal/time-travel-internal.ts +89 -0
  35. package/src/internal/timeline-internal.ts +23 -103
  36. package/src/internal/transaction-internal.ts +14 -5
  37. package/src/react/index.ts +28 -46
  38. package/src/react-devtools/AtomIODevtools.tsx +107 -0
  39. package/src/react-devtools/StateEditor.tsx +73 -0
  40. package/src/react-devtools/TokenList.tsx +49 -0
  41. package/src/react-devtools/devtools.scss +130 -0
  42. package/src/react-devtools/index.ts +1 -0
  43. package/src/react-explorer/AtomIOExplorer.tsx +208 -0
  44. package/src/react-explorer/explorer-effects.ts +20 -0
  45. package/src/react-explorer/explorer-states.ts +224 -0
  46. package/src/react-explorer/index.ts +23 -0
  47. package/src/react-explorer/space-states.ts +73 -0
  48. package/src/react-explorer/view-states.ts +43 -0
  49. package/src/selector.ts +6 -6
  50. package/src/subscribe.ts +2 -2
  51. package/src/timeline.ts +1 -5
  52. package/src/transaction.ts +2 -2
  53. package/src/web-effects/index.ts +1 -0
  54. package/src/web-effects/storage.ts +30 -0
@@ -0,0 +1,1551 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a2, b2) => {
9
+ for (var prop in b2 || (b2 = {}))
10
+ if (__hasOwnProp.call(b2, prop))
11
+ __defNormalProp(a2, prop, b2[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b2)) {
14
+ if (__propIsEnum.call(b2, prop))
15
+ __defNormalProp(a2, prop, b2[prop]);
16
+ }
17
+ return a2;
18
+ };
19
+ var __spreadProps = (a2, b2) => __defProps(a2, __getOwnPropDescs(b2));
20
+ var __restKey = (key) => typeof key === "symbol" ? key : key + "";
21
+ var __objRest = (source, exclude) => {
22
+ var target = {};
23
+ for (var prop in source)
24
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
25
+ target[prop] = source[prop];
26
+ if (source != null && __getOwnPropSymbols)
27
+ for (var prop of __getOwnPropSymbols(source)) {
28
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
29
+ target[prop] = source[prop];
30
+ }
31
+ return target;
32
+ };
33
+
34
+ // ../src/react-devtools/AtomIODevtools.tsx
35
+ import { useRef as useRef4 } from "react";
36
+ import { atom, __INTERNAL__ } from "atom.io";
37
+ import { useI, useO, useIO } from "atom.io/react";
38
+ import { LayoutGroup, motion, spring } from "framer-motion";
39
+
40
+ // ../src/react-devtools/TokenList.tsx
41
+ import { Fragment as Fragment3 } from "react";
42
+
43
+ // ../../anvl/src/object/index.ts
44
+ import { pipe as pipe3 } from "fp-ts/function";
45
+
46
+ // ../../anvl/src/object/refinement.ts
47
+ import { pipe as pipe2 } from "fp-ts/function";
48
+
49
+ // ../../anvl/src/object/access.ts
50
+ var access = (k) => Object.assign((obj) => obj[k], {
51
+ in: (obj) => obj[k]
52
+ });
53
+
54
+ // ../../anvl/src/object/entries.ts
55
+ var recordToEntries = (obj) => Object.entries(obj);
56
+ var entriesToRecord = (entries) => Object.fromEntries(entries);
57
+
58
+ // ../../anvl/src/object/mapObject.ts
59
+ import { pipe } from "fp-ts/lib/function";
60
+
61
+ // ../../anvl/src/array/index.ts
62
+ var isArray = (isType) => (input) => Array.isArray(input) && input.every((item) => isType(item));
63
+ var map = (f) => (a2) => a2.map(f);
64
+ var every = (f = Boolean) => (a2) => a2.every(f);
65
+ var allTrue = every((x) => x === true);
66
+
67
+ // ../../anvl/src/object/mapObject.ts
68
+ var mapObject = (obj, fn) => pipe(
69
+ obj,
70
+ recordToEntries,
71
+ map(([key, val]) => [key, fn(val, key)]),
72
+ entriesToRecord
73
+ );
74
+ var mob = (fn) => (obj) => mapObject(obj, fn);
75
+
76
+ // ../../anvl/src/function/index.ts
77
+ var doNothing = () => void 0;
78
+ var become = (nextVersionOfThing) => (originalThing) => nextVersionOfThing instanceof Function ? nextVersionOfThing(
79
+ originalThing instanceof Function ? originalThing() : originalThing
80
+ ) : nextVersionOfThing;
81
+ var pass = (...params) => (fn) => fn(...params);
82
+ var raiseError = (message) => {
83
+ throw new Error(message);
84
+ };
85
+ var attempt = (fn) => {
86
+ try {
87
+ fn();
88
+ return true;
89
+ } catch (_) {
90
+ return false;
91
+ }
92
+ };
93
+
94
+ // ../../anvl/src/nullish/index.ts
95
+ var isUndefined = (input) => input === void 0;
96
+ var ifDefined = (validate) => (input) => isUndefined(input) || validate(input);
97
+ var ifNullish = (alt) => (input) => input != null ? input : alt;
98
+
99
+ // ../../anvl/src/object/refinement.ts
100
+ var isNonNullObject = (input) => typeof input === `object` && input !== null;
101
+ var isPlainObject = (input) => isNonNullObject(input) && Object.getPrototypeOf(input) === Object.prototype;
102
+ var isRecord = (isKey, isValue) => (input) => isPlainObject(input) && Object.entries(input).every(([k, v]) => isKey(k) && isValue(v));
103
+ var hasProperties = (isValue, options = { allowExtraProperties: false }) => {
104
+ const name = `{${recordToEntries(
105
+ isValue
106
+ ).map(([k, v]) => String(k) + `:` + v.name).join(`,`)}}`;
107
+ const _ = {
108
+ [name]: (input) => isPlainObject(input) && pipe2(
109
+ isValue,
110
+ Object.entries,
111
+ every(([key, val]) => key in input || val(void 0))
112
+ ) && pipe2(
113
+ input,
114
+ mob(
115
+ (val, key) => pipe2(
116
+ isValue,
117
+ access(key),
118
+ ifNullish(() => options.allowExtraProperties),
119
+ pass(val)
120
+ )
121
+ ),
122
+ Object.values,
123
+ allTrue
124
+ )
125
+ };
126
+ return _[name];
127
+ };
128
+ var doesExtend = (
129
+ /* alias for hasExactProperties with allowExtraProperties */
130
+ (isValue) => hasProperties(isValue, { allowExtraProperties: true })
131
+ );
132
+
133
+ // ../../anvl/src/object/index.ts
134
+ var delve = (obj, path) => {
135
+ const found = path.reduce((acc, key) => acc == null ? void 0 : acc[key], obj);
136
+ return found === void 0 ? new Error(`Not found`) : { found };
137
+ };
138
+
139
+ // ../../anvl/src/json/index.ts
140
+ import { pipe as pipe4 } from "fp-ts/function";
141
+
142
+ // ../../anvl/src/json/refine.ts
143
+ import { isBoolean } from "fp-ts/boolean";
144
+ import { isNumber } from "fp-ts/number";
145
+ import { isString } from "fp-ts/string";
146
+ var refineJsonType = (data) => data === null ? { type: `null`, data: null } : isBoolean(data) ? { type: `boolean`, data } : isNumber(data) ? { type: `number`, data } : isString(data) ? { type: `string`, data } : Array.isArray(data) ? { type: `array`, data } : isPlainObject(data) ? { type: `object`, data } : raiseError(
147
+ data === void 0 ? `undefined passed to refineJsonType. This is not valid JSON.` : `${stringifyJson(data)} with prototype "${Object.getPrototypeOf(data).constructor.name}" passed to refineJsonType. This is not valid JSON.`
148
+ );
149
+ var isJson = (input) => {
150
+ try {
151
+ JSON.stringify(input);
152
+ return true;
153
+ } catch (e) {
154
+ return false;
155
+ }
156
+ };
157
+ var isPlainJson = (input) => attempt(() => isJson(input) && refineJsonType(input));
158
+
159
+ // ../../anvl/src/json/index.ts
160
+ var stringifyJson = (json) => JSON.stringify(json);
161
+ var JSON_TYPE_NAMES = [
162
+ `array`,
163
+ `boolean`,
164
+ `null`,
165
+ `number`,
166
+ `object`,
167
+ `string`
168
+ ];
169
+ var JSON_DEFAULTS = {
170
+ array: [],
171
+ boolean: false,
172
+ null: null,
173
+ number: 0,
174
+ object: {},
175
+ string: ``
176
+ };
177
+
178
+ // ../../hamr/src/react-elastic-input/ElasticInput.tsx
179
+ import {
180
+ useLayoutEffect,
181
+ useImperativeHandle,
182
+ forwardRef,
183
+ useRef,
184
+ useState
185
+ } from "react";
186
+ import { jsx, jsxs } from "@emotion/react/jsx-runtime";
187
+ var ElasticInput = forwardRef(function ElasticInputFC(props, ref) {
188
+ var _a2, _b, _c, _d;
189
+ const inputRef = useRef(null);
190
+ const spanRef = useRef(null);
191
+ const [inputWidth, setInputWidth] = useState(`auto`);
192
+ useImperativeHandle(ref, () => ({
193
+ focus: () => {
194
+ var _a3;
195
+ (_a3 = inputRef.current) == null ? void 0 : _a3.focus();
196
+ }
197
+ }));
198
+ const extraWidth = props.type === `number` ? 15 : 0;
199
+ useLayoutEffect(() => {
200
+ if (spanRef.current) {
201
+ setInputWidth(`${spanRef.current.offsetWidth + extraWidth}px`);
202
+ const interval = setInterval(() => {
203
+ if (spanRef.current) {
204
+ setInputWidth(`${spanRef.current.offsetWidth + extraWidth}px`);
205
+ }
206
+ }, 1e3);
207
+ return () => clearInterval(interval);
208
+ }
209
+ }, [(_a2 = inputRef.current) == null ? void 0 : _a2.value, props.value]);
210
+ return /* @__PURE__ */ jsxs("div", { style: { display: `inline-block`, position: `relative` }, children: [
211
+ /* @__PURE__ */ jsx(
212
+ "input",
213
+ __spreadProps(__spreadValues({}, props), {
214
+ ref: inputRef,
215
+ style: __spreadValues({
216
+ padding: 0,
217
+ borderRadius: 0,
218
+ border: `none`,
219
+ fontFamily: `inherit`,
220
+ fontSize: `inherit`,
221
+ width: inputWidth
222
+ }, props.style)
223
+ })
224
+ ),
225
+ /* @__PURE__ */ jsx(
226
+ "span",
227
+ {
228
+ ref: spanRef,
229
+ style: {
230
+ padding: (_b = props.style) == null ? void 0 : _b.padding,
231
+ position: `absolute`,
232
+ visibility: `hidden`,
233
+ // color: `red`,
234
+ whiteSpace: `pre`,
235
+ fontFamily: ((_c = props.style) == null ? void 0 : _c.fontFamily) || `inherit`,
236
+ fontSize: ((_d = props.style) == null ? void 0 : _d.fontSize) || `inherit`
237
+ },
238
+ children: props.value
239
+ }
240
+ )
241
+ ] });
242
+ });
243
+
244
+ // ../../hamr/src/react-elastic-input/NumberInput.tsx
245
+ import { useState as useState2, useId, useRef as useRef2 } from "react";
246
+ import { pipe as pipe5 } from "fp-ts/function";
247
+
248
+ // ../../anvl/src/number/clamp.ts
249
+ var clampInto = ([min, max]) => (value) => value < min ? min : value > max ? max : value;
250
+
251
+ // ../../hamr/src/react-elastic-input/NumberInput.tsx
252
+ import { jsx as jsx2, jsxs as jsxs2 } from "@emotion/react/jsx-runtime";
253
+ function round(value, decimalPlaces) {
254
+ if (decimalPlaces === void 0)
255
+ return value;
256
+ const factor = Math.pow(10, decimalPlaces);
257
+ return Math.round(value * factor) / factor;
258
+ }
259
+ var VALID_NON_NUMBERS = [``, `-`, `.`, `-.`];
260
+ var isValidNonNumber = (input) => VALID_NON_NUMBERS.includes(input);
261
+ var VALID_NON_NUMBER_INTERPRETATIONS = {
262
+ "": null,
263
+ "-": 0,
264
+ ".": 0,
265
+ "-.": 0
266
+ };
267
+ var isDecimalInProgress = (input) => input === `0` || !isNaN(Number(input)) && input.includes(`.`);
268
+ var textToValue = (input, allowDecimal) => {
269
+ if (isValidNonNumber(input))
270
+ return VALID_NON_NUMBER_INTERPRETATIONS[input];
271
+ return allowDecimal ? parseFloat(input) : Math.round(parseFloat(input));
272
+ };
273
+ var DEFAULT_NUMBER_CONSTRAINTS = {
274
+ max: Infinity,
275
+ min: -Infinity,
276
+ decimalPlaces: 100,
277
+ nullable: true
278
+ };
279
+ var initRefinery = (constraints) => (input) => {
280
+ if (input === null && constraints.nullable === true) {
281
+ return null;
282
+ }
283
+ const { max, min, decimalPlaces } = __spreadValues(__spreadValues({}, DEFAULT_NUMBER_CONSTRAINTS), constraints);
284
+ const constrained = pipe5(
285
+ input != null ? input : 0,
286
+ clampInto([min, max]),
287
+ (n) => decimalPlaces ? round(n, decimalPlaces) : n
288
+ );
289
+ return constrained;
290
+ };
291
+ var valueToText = (numericValue) => {
292
+ if (numericValue === null || numericValue === void 0) {
293
+ return ``;
294
+ }
295
+ return numericValue.toString();
296
+ };
297
+ var NumberInput = ({
298
+ autoSize = false,
299
+ customCss,
300
+ decimalPlaces,
301
+ disabled = false,
302
+ label,
303
+ max,
304
+ min,
305
+ name,
306
+ onChange,
307
+ onClick,
308
+ placeholder = ``,
309
+ set = () => null,
310
+ testId,
311
+ value = null
312
+ }) => {
313
+ const id = useId();
314
+ const [temporaryEntry, setTemporaryEntry] = useState2(null);
315
+ const userHasMadeDeliberateChange = useRef2(false);
316
+ const refine = initRefinery({ max, min, decimalPlaces, nullable: true });
317
+ const allowDecimal = decimalPlaces === void 0 || decimalPlaces > 0;
318
+ const handleBlur = () => {
319
+ if (userHasMadeDeliberateChange.current) {
320
+ set(refine(value != null ? value : null));
321
+ setTemporaryEntry(null);
322
+ }
323
+ userHasMadeDeliberateChange.current = false;
324
+ };
325
+ const handleChange = (event) => {
326
+ var _a2;
327
+ if (onChange)
328
+ onChange(event);
329
+ if (set === void 0)
330
+ return;
331
+ userHasMadeDeliberateChange.current = true;
332
+ const input = event.target.value;
333
+ if (isValidNonNumber(input) || isDecimalInProgress(input)) {
334
+ setTemporaryEntry(input);
335
+ const textInterpretation = isDecimalInProgress(input) ? input : (_a2 = min == null ? void 0 : min.toString()) != null ? _a2 : `0`;
336
+ const newValue = textToValue(textInterpretation, allowDecimal);
337
+ set(refine(newValue));
338
+ return;
339
+ }
340
+ setTemporaryEntry(null);
341
+ const inputIsNumeric = !isNaN(Number(input)) && !input.includes(` `) || allowDecimal && input === `.` || allowDecimal && input === `-.` || input === `` || input === `-`;
342
+ const numericValue = textToValue(input, allowDecimal);
343
+ if (inputIsNumeric) {
344
+ set(refine(numericValue));
345
+ }
346
+ };
347
+ const displayValue = temporaryEntry != null ? temporaryEntry : valueToText(value ? refine(value) : value);
348
+ return /* @__PURE__ */ jsxs2("span", { css: customCss, children: [
349
+ label && /* @__PURE__ */ jsx2("label", { htmlFor: id, children: label }),
350
+ autoSize ? /* @__PURE__ */ jsx2(
351
+ ElasticInput,
352
+ {
353
+ type: "text",
354
+ value: displayValue,
355
+ placeholder: placeholder != null ? placeholder : `-`,
356
+ onChange: handleChange,
357
+ onBlur: handleBlur,
358
+ disabled,
359
+ name: name != null ? name : id,
360
+ id,
361
+ onClick,
362
+ "data-testid": `number-input-${testId != null ? testId : id}`
363
+ }
364
+ ) : /* @__PURE__ */ jsx2(
365
+ "input",
366
+ {
367
+ type: "text",
368
+ value: displayValue,
369
+ placeholder: placeholder != null ? placeholder : `-`,
370
+ onChange: handleChange,
371
+ onBlur: handleBlur,
372
+ disabled,
373
+ name: name != null ? name : id,
374
+ id,
375
+ onClick,
376
+ "data-testid": `number-input-${testId != null ? testId : id}`
377
+ }
378
+ )
379
+ ] });
380
+ };
381
+
382
+ // ../../hamr/src/react-elastic-input/TextInput.tsx
383
+ import { jsx as jsx3, jsxs as jsxs3 } from "@emotion/react/jsx-runtime";
384
+ var TextInput = ({
385
+ value,
386
+ set,
387
+ label,
388
+ placeholder,
389
+ customCss,
390
+ autoSize = false
391
+ }) => {
392
+ return /* @__PURE__ */ jsxs3("span", { css: customCss, children: [
393
+ /* @__PURE__ */ jsx3("label", { children: label }),
394
+ autoSize ? /* @__PURE__ */ jsx3(
395
+ ElasticInput,
396
+ {
397
+ type: "text",
398
+ value,
399
+ onChange: (e) => set == null ? void 0 : set(e.target.value),
400
+ disabled: set === void 0,
401
+ placeholder
402
+ }
403
+ ) : /* @__PURE__ */ jsx3(
404
+ "input",
405
+ {
406
+ type: "text",
407
+ value,
408
+ onChange: (e) => set == null ? void 0 : set(e.target.value),
409
+ disabled: set === void 0,
410
+ placeholder
411
+ }
412
+ )
413
+ ] });
414
+ };
415
+
416
+ // ../../hamr/src/react-json-editor/editors-by-type/utilities/array-elements.ts
417
+ var makeElementSetters = (data, set) => data.map(
418
+ (value, index) => (newValue) => set(() => {
419
+ const newData = [...data];
420
+ newData[index] = become(newValue)(value);
421
+ return newData;
422
+ })
423
+ );
424
+
425
+ // ../../hamr/src/react-json-editor/json-editor-internal.tsx
426
+ import { jsx as jsx4, jsxs as jsxs4 } from "@emotion/react/jsx-runtime";
427
+ var JsonEditor_INTERNAL = ({
428
+ data,
429
+ set,
430
+ schema,
431
+ name,
432
+ rename,
433
+ remove,
434
+ recast,
435
+ path = [],
436
+ isReadonly = () => false,
437
+ isHidden = () => false,
438
+ className,
439
+ customCss,
440
+ Header: HeaderDisplay,
441
+ Components
442
+ }) => {
443
+ const json = refineJsonType(data);
444
+ const SubEditor = SubEditors[json.type];
445
+ const disabled = isReadonly(path);
446
+ return isHidden(path) ? null : /* @__PURE__ */ jsx4(Components.ErrorBoundary, { children: /* @__PURE__ */ jsxs4(Components.EditorWrapper, { className, customCss, children: [
447
+ remove && /* @__PURE__ */ jsx4(
448
+ Components.Button,
449
+ {
450
+ onClick: disabled ? doNothing : remove,
451
+ disabled,
452
+ children: /* @__PURE__ */ jsx4(Components.DeleteIcon, {})
453
+ }
454
+ ),
455
+ HeaderDisplay && /* @__PURE__ */ jsx4(HeaderDisplay, { data, schema }),
456
+ rename && /* @__PURE__ */ jsx4(Components.KeyWrapper, { children: /* @__PURE__ */ jsx4(
457
+ ElasticInput,
458
+ {
459
+ value: name,
460
+ onChange: disabled ? doNothing : (e) => rename(e.target.value),
461
+ disabled
462
+ }
463
+ ) }),
464
+ /* @__PURE__ */ jsx4(
465
+ SubEditor,
466
+ {
467
+ data: json.data,
468
+ set,
469
+ schema,
470
+ remove,
471
+ rename,
472
+ path,
473
+ isReadonly,
474
+ isHidden,
475
+ Components
476
+ }
477
+ ),
478
+ recast && /* @__PURE__ */ jsx4(
479
+ "select",
480
+ {
481
+ onChange: disabled ? doNothing : (e) => recast(e.target.value),
482
+ value: json.type,
483
+ disabled,
484
+ children: Object.keys(SubEditors).map((type) => /* @__PURE__ */ jsx4("option", { value: type, children: type }, type))
485
+ }
486
+ )
487
+ ] }) });
488
+ };
489
+
490
+ // ../../hamr/src/react-json-editor/editors-by-type/array-editor.tsx
491
+ import { Fragment, jsx as jsx5 } from "@emotion/react/jsx-runtime";
492
+ var ArrayEditor = ({
493
+ path = [],
494
+ isReadonly = () => false,
495
+ isHidden = () => false,
496
+ data,
497
+ set,
498
+ Components
499
+ }) => {
500
+ const setElement = makeElementSetters(data, set);
501
+ return /* @__PURE__ */ jsx5(Fragment, { children: data.map((element, index) => {
502
+ const newPath = [...path, index];
503
+ return /* @__PURE__ */ jsx5(
504
+ JsonEditor_INTERNAL,
505
+ {
506
+ path: newPath,
507
+ isReadonly,
508
+ isHidden,
509
+ data: element,
510
+ set: setElement[index],
511
+ Components
512
+ },
513
+ newPath.join(``)
514
+ );
515
+ }) });
516
+ };
517
+
518
+ // ../../hamr/src/react-json-editor/editors-by-type/object-editor.tsx
519
+ import { useRef as useRef3 } from "react";
520
+
521
+ // ../../anvl/src/json-schema/json-schema.ts
522
+ import { isBoolean as isBoolean2 } from "fp-ts/boolean";
523
+ import { isNumber as isNumber2 } from "fp-ts/number";
524
+ import { isString as isString4 } from "fp-ts/string";
525
+
526
+ // ../../anvl/src/json-schema/integer.ts
527
+ import { pipe as pipe6 } from "fp-ts/function";
528
+ var isInteger = (input) => Number.isInteger(input);
529
+ var parseInt = (input) => {
530
+ if (isInteger(input))
531
+ return input;
532
+ throw new IntegerParseError(input);
533
+ };
534
+ var _a;
535
+ var Fraction = class extends Number {
536
+ constructor(n, d) {
537
+ super(n / d);
538
+ this[_a] = () => this.numerator / this.denominator;
539
+ if (d === 0) {
540
+ throw new Error(`Denominator cannot be zero`);
541
+ }
542
+ this.numerator = parseInt(n);
543
+ this.denominator = parseInt(d);
544
+ }
545
+ };
546
+ _a = Symbol.toPrimitive;
547
+ var IntegerParseError = class extends Error {
548
+ constructor(value) {
549
+ super(`Could not parse integer from ${JSON.stringify(value)}`);
550
+ }
551
+ };
552
+ var Int = Object.assign((input) => parseInt(input), {
553
+ from: (input) => pipe6(
554
+ input,
555
+ String,
556
+ parseFloat,
557
+ (num) => isInteger(num) ? {
558
+ value: num,
559
+ error: null,
560
+ round: null,
561
+ upper: null,
562
+ lower: null,
563
+ ratio: null
564
+ } : {
565
+ value: null,
566
+ error: new IntegerParseError(input),
567
+ round: Math.round(num),
568
+ upper: Math.ceil(num),
569
+ lower: Math.floor(num),
570
+ ratio: null
571
+ }
572
+ ),
573
+ formula: (fm) => {
574
+ return (input) => {
575
+ return fm(
576
+ input
577
+ );
578
+ };
579
+ }
580
+ });
581
+ function asNumber(input) {
582
+ return input;
583
+ }
584
+ var a = asNumber(new Fraction(1, 2));
585
+ var b = asNumber([new Fraction(1, 2)]);
586
+ var c = asNumber({ a: new Fraction(1, 2) });
587
+
588
+ // ../../anvl/src/json-schema/refs.ts
589
+ import { isString as isString2 } from "fp-ts/string";
590
+ function isJsonSchemaRef(input) {
591
+ return doesExtend({
592
+ $ref: isString2
593
+ })(input);
594
+ }
595
+ var colorPalette = {
596
+ $defs: {
597
+ colorChannel: {
598
+ type: `integer`,
599
+ minimum: Int(0),
600
+ maximum: Int(255)
601
+ },
602
+ color: {
603
+ type: `object`,
604
+ properties: {
605
+ red: { $ref: `#/$defs/colorChannel` },
606
+ green: { $ref: `#/$defs/colorChannel` },
607
+ blue: { $ref: `#/$defs/colorChannel` }
608
+ }
609
+ }
610
+ },
611
+ type: `array`,
612
+ items: {
613
+ $ref: `#/$defs/color`
614
+ }
615
+ };
616
+ var retrieveRef = ({
617
+ refNode: { $ref },
618
+ refMap = {},
619
+ root
620
+ }) => {
621
+ if (typeof root === `boolean`) {
622
+ throw new TypeError(`The root is a boolean and cannot be indexed`);
623
+ }
624
+ if ($ref in refMap)
625
+ return { node: refMap[$ref], refMap };
626
+ const [_, ...refPath] = $ref.split(`/`);
627
+ const discovery = delve(root, refPath);
628
+ if (discovery instanceof Error)
629
+ throw discovery;
630
+ let node = discovery.found;
631
+ while (isJsonSchemaRef(node)) {
632
+ const result = retrieveRef({ refNode: node, refMap, root });
633
+ node = result.node;
634
+ refMap = result.refMap;
635
+ }
636
+ if (isJsonSchema(node)) {
637
+ return { node, refMap: __spreadProps(__spreadValues({}, refMap), { [$ref]: node }) };
638
+ }
639
+ throw new TypeError(`The refNode is not a JsonSchema`);
640
+ };
641
+
642
+ // ../../anvl/src/json-schema/string-formats.ts
643
+ import { isString as isString3 } from "fp-ts/string";
644
+ var JSON_SCHEMA_STRING_FORMATS = [
645
+ `date-time`,
646
+ `date`,
647
+ `email`,
648
+ `hostname`,
649
+ `ipv4`,
650
+ `ipv6`,
651
+ `regex`,
652
+ `time`,
653
+ `uri-reference`,
654
+ `uri-template`,
655
+ `uri`,
656
+ `uuid`
657
+ ];
658
+
659
+ // ../../anvl/src/refinement/index.ts
660
+ var canExist = (_) => true;
661
+ var cannotExist = (_) => false;
662
+ var isLiteral = (value) => (input) => input === value;
663
+ var isWithin = (args) => (input) => args.includes(input);
664
+ var couldBe = (isTypeA, logging = false, refinements = [isTypeA]) => {
665
+ const name = `(${refinements.map((r) => r.name || `anon`).join(` | `)})`;
666
+ const _ = {
667
+ [name]: (input) => refinements.some(
668
+ (refinement) => {
669
+ var _a2;
670
+ return logging && console.log(
671
+ refinements.map((r) => r.name || `anon`).join(` | `),
672
+ `>`,
673
+ (_a2 = refinement.name) != null ? _a2 : `anon`,
674
+ `:`,
675
+ refinement(input)
676
+ ), refinement(input);
677
+ }
678
+ )
679
+ };
680
+ const checkTypes = Object.assign(_[name], {
681
+ or: (isTypeB) => couldBe(isTypeB, logging, [...refinements, isTypeB])
682
+ });
683
+ return checkTypes;
684
+ };
685
+ var isUnion = couldBe(cannotExist);
686
+ var mustBe = (isTypeA, logging = false, refinements = [isTypeA]) => {
687
+ const name = `(${refinements.map((r) => r.name || `anon`).join(` & `)})`;
688
+ const _ = {
689
+ [name]: (input) => refinements.every(
690
+ (refinement) => (logging && console.log(
691
+ refinements.map((r) => r.name || `anon`).join(` & `),
692
+ `>`,
693
+ refinement.name || `anon`,
694
+ `:`,
695
+ refinement(input)
696
+ ), refinement(input))
697
+ )
698
+ };
699
+ const checkTypes = Object.assign(_[name], {
700
+ and: (isTypeB) => mustBe(isTypeB, logging, [...refinements, isTypeB])
701
+ });
702
+ return checkTypes;
703
+ };
704
+ var isIntersection = mustBe(canExist);
705
+
706
+ // ../../anvl/src/json-schema/json-schema.ts
707
+ var JSON_SCHEMA_TYPE_NAMES = [...JSON_TYPE_NAMES, `integer`];
708
+ var JSON_SCHEMA_META_TYPE_NAMES = [
709
+ ...JSON_SCHEMA_TYPE_NAMES,
710
+ `any`,
711
+ `never`
712
+ ];
713
+ var JSON_SCHEMA_REFINERY = {
714
+ array: isArraySchema,
715
+ boolean: isBooleanSchema,
716
+ integer: isIntegerSchema,
717
+ null: isNullSchema,
718
+ number: isNumberSchema,
719
+ object: isObjectSchema,
720
+ string: isStringSchema,
721
+ any: isLiteral(true),
722
+ never: isLiteral(false),
723
+ union: isUnionSchema,
724
+ intersection: isIntersectionSchema,
725
+ negation: isNegationSchema,
726
+ conditional: isConditionalSchema
727
+ };
728
+ var stringSchemaStructure = {
729
+ type: isLiteral(`string`),
730
+ enum: ifDefined(isArray(isString4)),
731
+ minLength: ifDefined(isInteger),
732
+ maxLength: ifDefined(isInteger),
733
+ pattern: ifDefined(isString4),
734
+ format: ifDefined(isWithin(JSON_SCHEMA_STRING_FORMATS))
735
+ };
736
+ function isStringSchema(input) {
737
+ return doesExtend(stringSchemaStructure)(input);
738
+ }
739
+ var numberSchemaStructure = {
740
+ type: isLiteral(`number`),
741
+ enum: ifDefined(isArray(isNumber2)),
742
+ minimum: ifDefined(isNumber2),
743
+ maximum: ifDefined(isNumber2),
744
+ exclusiveMinimum: ifDefined(isNumber2),
745
+ exclusiveMaximum: ifDefined(isNumber2),
746
+ multipleOf: ifDefined(isNumber2)
747
+ };
748
+ function isNumberSchema(input) {
749
+ return doesExtend(numberSchemaStructure)(input);
750
+ }
751
+ var integerSchemaStructure = {
752
+ type: isLiteral(`integer`),
753
+ enum: ifDefined(isArray(isInteger)),
754
+ minimum: ifDefined(isInteger),
755
+ maximum: ifDefined(isInteger),
756
+ exclusiveMinimum: ifDefined(isInteger),
757
+ exclusiveMaximum: ifDefined(isInteger),
758
+ multipleOf: ifDefined(isInteger)
759
+ };
760
+ function isIntegerSchema(input) {
761
+ return doesExtend(integerSchemaStructure)(input);
762
+ }
763
+ var booleanSchemaStructure = {
764
+ type: isLiteral(`boolean`),
765
+ enum: ifDefined(isArray(isBoolean2))
766
+ };
767
+ function isBooleanSchema(input) {
768
+ return doesExtend(booleanSchemaStructure)(input);
769
+ }
770
+ var nullSchemaStructure = {
771
+ type: isLiteral(`null`)
772
+ };
773
+ function isNullSchema(input) {
774
+ return doesExtend(nullSchemaStructure)(input);
775
+ }
776
+ var objectSchemaStructure = {
777
+ type: isLiteral(`object`),
778
+ properties: ifDefined(isRecord(isString4, isJsonSchema)),
779
+ required: ifDefined(isArray(isString4)),
780
+ additionalProperties: ifDefined(isJsonSchema),
781
+ propertyNames: ifDefined(isStringSchema),
782
+ minProperties: ifDefined(isInteger),
783
+ maxProperties: ifDefined(isInteger),
784
+ dependentSchemas: ifDefined(isRecord(isString4, isJsonSchema))
785
+ };
786
+ function isObjectSchema(input) {
787
+ return doesExtend(objectSchemaStructure)(input);
788
+ }
789
+ var arraySchemaStructure = {
790
+ type: isLiteral(`array`),
791
+ items: ifDefined(couldBe(isJsonSchema).or(isArray(isJsonSchema))),
792
+ minItems: ifDefined(isInteger),
793
+ maxItems: ifDefined(isInteger),
794
+ uniqueItems: ifDefined(isBoolean2)
795
+ };
796
+ function isArraySchema(input) {
797
+ return doesExtend(arraySchemaStructure)(input);
798
+ }
799
+ var unionSchemaStructure = { anyOf: isArray(isJsonSchema) };
800
+ function isUnionSchema(input) {
801
+ return doesExtend(unionSchemaStructure)(input);
802
+ }
803
+ var exclusiveSchemaStructure = { oneOf: isArray(isJsonSchema) };
804
+ function isExclusiveSchema(input) {
805
+ return doesExtend(exclusiveSchemaStructure)(input);
806
+ }
807
+ var intersectionSchemaStructure = { allOf: isArray(isJsonSchema) };
808
+ function isIntersectionSchema(input) {
809
+ return doesExtend(intersectionSchemaStructure)(input);
810
+ }
811
+ var conditionalSchemaStructure = {
812
+ if: isJsonSchema,
813
+ then: ifDefined(isJsonSchema),
814
+ else: ifDefined(isJsonSchema)
815
+ };
816
+ function isConditionalSchema(input) {
817
+ return doesExtend(conditionalSchemaStructure)(input);
818
+ }
819
+ var negationSchemaStructure = { not: isJsonSchema };
820
+ function isNegationSchema(input) {
821
+ return doesExtend(negationSchemaStructure)(input);
822
+ }
823
+ var mixedSchemaStructure = __spreadProps(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, arraySchemaStructure), booleanSchemaStructure), integerSchemaStructure), nullSchemaStructure), numberSchemaStructure), objectSchemaStructure), stringSchemaStructure), {
824
+ type: isArray(isWithin(JSON_SCHEMA_TYPE_NAMES)),
825
+ enum: ifDefined(
826
+ isArray(isUnion.or(isInteger).or(isBoolean2).or(isNumber2).or(isString4))
827
+ )
828
+ });
829
+ function isMixedSchema(input) {
830
+ return doesExtend(mixedSchemaStructure)(input);
831
+ }
832
+ var isJsonSchemaCore = isUnion.or(isArraySchema).or(isBooleanSchema).or(isConditionalSchema).or(isExclusiveSchema).or(isIntegerSchema).or(isIntersectionSchema).or(isMixedSchema).or(isNegationSchema).or(isNullSchema).or(isNumberSchema).or(isObjectSchema).or(isStringSchema).or(isUnionSchema);
833
+ var isJsonSchemaRoot = doesExtend({
834
+ $id: ifDefined(isString4),
835
+ $schema: ifDefined(isString4)
836
+ });
837
+ var isJsonSchemaObject = isIntersection.and(isJsonSchemaCore).and(isJsonSchemaRoot);
838
+ function isJsonSchema(input) {
839
+ return couldBe(isJsonSchemaObject).or(isBoolean2).or(isJsonSchemaRef)(input);
840
+ }
841
+
842
+ // ../../anvl/src/json-schema/path-into.ts
843
+ var expandPathForSchema = (path) => {
844
+ try {
845
+ return path.map((key) => {
846
+ switch (typeof key) {
847
+ case `string`:
848
+ return [`properties`, key];
849
+ case `number`:
850
+ return [`items`, key];
851
+ case `symbol`:
852
+ throw new TypeError(
853
+ `The key ${String(
854
+ key
855
+ )} is not a valid JSON key; expected string or number, got symbol`
856
+ );
857
+ default:
858
+ throw new TypeError(
859
+ `The key ${key} is not a valid JSON key; expected string or number, got ${typeof key}`
860
+ );
861
+ }
862
+ }).flat();
863
+ } catch (caught) {
864
+ if (caught instanceof TypeError)
865
+ return caught;
866
+ throw caught;
867
+ }
868
+ };
869
+
870
+ // ../../anvl/src/json-schema/find-sub-schema.ts
871
+ var findSubSchema = (schema) => {
872
+ if (typeof schema === `boolean`) {
873
+ throw new Error(`The schema does not contain subSchemas`);
874
+ }
875
+ return (path) => {
876
+ const pathIntoSchema = expandPathForSchema(path);
877
+ if (pathIntoSchema instanceof Error)
878
+ return pathIntoSchema;
879
+ if (typeof schema === `boolean`) {
880
+ return new TypeError(`The schema is not a JsonSchema`);
881
+ }
882
+ const { node, refMap } = pathIntoSchema.reduce(
883
+ ({ node: node2, refMap: refMap2 = void 0 }, key) => (console.log({ node: node2, key }), isJsonSchemaRef(node2) ? retrieveRef({ refNode: node2, root: schema, refMap: refMap2 }) : { node: node2[key], refMap: refMap2 }),
884
+ { node: schema, refMap: void 0 }
885
+ );
886
+ if (node instanceof Error)
887
+ throw node;
888
+ let subSchema = node;
889
+ while (isJsonSchemaRef(subSchema)) {
890
+ console.log({ subSchema });
891
+ subSchema = retrieveRef({ refNode: subSchema, root: schema, refMap }).node;
892
+ }
893
+ console.log({ subSchema });
894
+ if (isJsonSchema(subSchema)) {
895
+ return subSchema;
896
+ }
897
+ throw new TypeError(`The subSchema is not a JsonSchema`);
898
+ };
899
+ };
900
+
901
+ // ../../anvl/src/json/cast.ts
902
+ var stringToBoolean = (str) => str === `true`;
903
+ var stringToNumber = (str) => Number(str);
904
+ var stringToArray = (str) => str.split(`,`);
905
+ var stringToObject = (str) => {
906
+ try {
907
+ return JSON.parse(str);
908
+ } catch (e) {
909
+ return { [str]: str };
910
+ }
911
+ };
912
+ var objectToString = (obj) => JSON.stringify(obj);
913
+ var objectToBoolean = (obj) => obj.true === true;
914
+ var objectToNumber = (obj) => {
915
+ var _a2, _b, _c;
916
+ return Number((_c = (_b = (_a2 = obj.number) != null ? _a2 : obj.size) != null ? _b : obj.count) != null ? _c : 0);
917
+ };
918
+ var objectToArray = (obj) => Object.entries(obj);
919
+ var booleanToString = (bool) => bool.toString();
920
+ var booleanToNumber = (bool) => +bool;
921
+ var booleanToObject = (bool) => ({
922
+ [bool.toString()]: bool
923
+ });
924
+ var booleanToArray = (bool) => [bool];
925
+ var numberToString = (num) => num.toString();
926
+ var numberToBoolean = (num) => num === 1;
927
+ var numberToObject = (num) => ({
928
+ number: num
929
+ });
930
+ var numberToArray = (num) => Array(num).fill(null);
931
+ var arrayToString = (arr) => arr.join(`,`);
932
+ var arrayToNumber = (arr) => arr.length;
933
+ var arrayToBoolean = (arr) => typeof arr[0] === `boolean` ? arr[0] : arr.length > 0;
934
+ var arrayToObject = (arr) => arr.reduce((acc, cur, idx) => {
935
+ acc[`${idx}`] = cur;
936
+ return acc;
937
+ }, {});
938
+ var nullToString = () => ``;
939
+ var nullToNumber = () => 0;
940
+ var nullToBoolean = () => false;
941
+ var nullToArray = () => [];
942
+ var nullToObject = () => ({});
943
+ var cast = (input) => {
944
+ const json = refineJsonType(input);
945
+ return {
946
+ to: {
947
+ array: () => {
948
+ switch (json.type) {
949
+ case `array`:
950
+ return json.data;
951
+ case `object`:
952
+ return objectToArray(json.data);
953
+ case `string`:
954
+ return stringToArray(json.data);
955
+ case `boolean`:
956
+ return booleanToArray(json.data);
957
+ case `number`:
958
+ return numberToArray(json.data);
959
+ case `null`:
960
+ return nullToArray();
961
+ }
962
+ },
963
+ boolean: () => {
964
+ switch (json.type) {
965
+ case `array`:
966
+ return arrayToBoolean(json.data);
967
+ case `object`:
968
+ return objectToBoolean(json.data);
969
+ case `string`:
970
+ return stringToBoolean(json.data);
971
+ case `boolean`:
972
+ return json.data;
973
+ case `number`:
974
+ return numberToBoolean(json.data);
975
+ case `null`:
976
+ return nullToBoolean();
977
+ }
978
+ },
979
+ number: () => {
980
+ switch (json.type) {
981
+ case `array`:
982
+ return arrayToNumber(json.data);
983
+ case `object`:
984
+ return objectToNumber(json.data);
985
+ case `string`:
986
+ return stringToNumber(json.data);
987
+ case `boolean`:
988
+ return booleanToNumber(json.data);
989
+ case `number`:
990
+ return json.data;
991
+ case `null`:
992
+ return nullToNumber();
993
+ }
994
+ },
995
+ object: () => {
996
+ switch (json.type) {
997
+ case `array`:
998
+ return arrayToObject(json.data);
999
+ case `object`:
1000
+ return json.data;
1001
+ case `string`:
1002
+ return stringToObject(json.data);
1003
+ case `boolean`:
1004
+ return booleanToObject(json.data);
1005
+ case `number`:
1006
+ return numberToObject(json.data);
1007
+ case `null`:
1008
+ return nullToObject();
1009
+ }
1010
+ },
1011
+ string: () => {
1012
+ switch (json.type) {
1013
+ case `array`:
1014
+ return arrayToString(json.data);
1015
+ case `object`:
1016
+ return objectToString(json.data);
1017
+ case `string`:
1018
+ return json.data;
1019
+ case `boolean`:
1020
+ return booleanToString(json.data);
1021
+ case `number`:
1022
+ return numberToString(json.data);
1023
+ case `null`:
1024
+ return nullToString();
1025
+ }
1026
+ },
1027
+ null: () => null
1028
+ }
1029
+ };
1030
+ };
1031
+
1032
+ // ../../Luum/src/utils/mapObject.ts
1033
+ var mapObject2 = (obj, fn) => {
1034
+ const newObj = {};
1035
+ const entries = Object.entries(obj);
1036
+ entries.forEach(([key, val]) => newObj[key] = fn(val, key));
1037
+ return newObj;
1038
+ };
1039
+ var mapObject_default = mapObject2;
1040
+
1041
+ // ../../hamr/src/react-json-editor/editors-by-type/utilities/object-properties.ts
1042
+ var makePropertySetters = (data, set) => mapObject_default(
1043
+ data,
1044
+ (value, key) => (newValue) => set(__spreadProps(__spreadValues({}, data), { [key]: become(newValue)(value[key]) }))
1045
+ );
1046
+ var makePropertyRenamers = (data, set, stableKeyMapRef) => mapObject_default(
1047
+ data,
1048
+ (value, key) => (newKey) => Object.hasOwn(data, newKey) ? null : set(() => {
1049
+ const entries = Object.entries(data);
1050
+ const index = entries.findIndex(([k]) => k === key);
1051
+ entries[index] = [newKey, value];
1052
+ const stableKeyMap = stableKeyMapRef.current;
1053
+ stableKeyMapRef.current = __spreadProps(__spreadValues({}, stableKeyMap), {
1054
+ [newKey]: stableKeyMap[key]
1055
+ });
1056
+ return Object.fromEntries(entries);
1057
+ })
1058
+ );
1059
+ var makePropertyRemovers = (data, set) => mapObject_default(
1060
+ data,
1061
+ (_, key) => () => set(() => {
1062
+ const _a2 = data, { [key]: _2 } = _a2, rest = __objRest(_a2, [__restKey(key)]);
1063
+ return rest;
1064
+ })
1065
+ );
1066
+ var makePropertyRecasters = (data, set) => mapObject_default(
1067
+ data,
1068
+ (value, key) => (newType) => set(() => __spreadProps(__spreadValues({}, data), {
1069
+ [key]: cast(value).to[newType]()
1070
+ }))
1071
+ );
1072
+ var makePropertyCreationInterface = (data, set) => (key, type) => (value) => set(__spreadProps(__spreadValues({}, data), { [key]: value != null ? value : JSON_DEFAULTS[type] }));
1073
+ var makePropertySorter = (data, set, sortFn) => () => {
1074
+ const sortedKeys = Object.keys(data).sort(sortFn);
1075
+ const sortedObj = {};
1076
+ sortedKeys.forEach((key) => sortedObj[key] = data[key]);
1077
+ set(sortedObj);
1078
+ };
1079
+
1080
+ // ../../hamr/src/react-json-editor/editors-by-type/object-editor.tsx
1081
+ import { Fragment as Fragment2, jsx as jsx6, jsxs as jsxs5 } from "@emotion/react/jsx-runtime";
1082
+ var PropertyAdder = ({
1083
+ addProperty,
1084
+ disabled,
1085
+ propertyKey,
1086
+ Components
1087
+ }) => /* @__PURE__ */ jsxs5(Components.MissingPropertyWrapper, { children: [
1088
+ /* @__PURE__ */ jsx6(ElasticInput, { disabled: true, defaultValue: propertyKey }),
1089
+ /* @__PURE__ */ jsx6(ElasticInput, { disabled: true, defaultValue: "is missing" }),
1090
+ /* @__PURE__ */ jsx6(Components.Button, { onClick: () => addProperty(), disabled, children: "+" })
1091
+ ] });
1092
+ var ObjectEditor = ({
1093
+ schema,
1094
+ path = [],
1095
+ isReadonly = () => false,
1096
+ isHidden = () => false,
1097
+ data,
1098
+ set,
1099
+ Components
1100
+ }) => {
1101
+ var _a2;
1102
+ const disabled = isReadonly(path);
1103
+ const stableKeyMap = useRef3(
1104
+ Object.keys(data).reduce((acc, key) => {
1105
+ acc[key] = key;
1106
+ return acc;
1107
+ }, {})
1108
+ );
1109
+ const setProperty = makePropertySetters(data, set);
1110
+ const renameProperty = makePropertyRenamers(data, set, stableKeyMap);
1111
+ const removeProperty = makePropertyRemovers(data, set);
1112
+ const recastProperty = makePropertyRecasters(data, set);
1113
+ const sortProperties = makePropertySorter(data, set);
1114
+ const makePropertyAdder = makePropertyCreationInterface(data, set);
1115
+ const subSchema = isPlainObject(schema) ? findSubSchema(schema)(path) : true;
1116
+ const schemaKeys = isLiteral(true)(subSchema) ? true : isObjectSchema(subSchema) ? Object.keys((_a2 = subSchema.properties) != null ? _a2 : {}) : [];
1117
+ const dataKeys = Object.keys(data);
1118
+ const [unofficialKeys, officialKeys] = dataKeys.reduce(
1119
+ ([unofficial, official], key) => {
1120
+ const isOfficial = schemaKeys === true || schemaKeys.includes(key);
1121
+ return isOfficial ? [unofficial, [...official, key]] : [[...unofficial, key], official];
1122
+ },
1123
+ [[], []]
1124
+ );
1125
+ const missingKeys = schemaKeys === true ? [] : schemaKeys.filter((key) => !dataKeys.includes(key));
1126
+ return /* @__PURE__ */ jsxs5(Fragment2, { children: [
1127
+ /* @__PURE__ */ jsx6(Components.Button, { onClick: () => sortProperties(), disabled, children: "Sort" }),
1128
+ /* @__PURE__ */ jsxs5(Components.ObjectWrapper, { children: [
1129
+ /* @__PURE__ */ jsx6("div", { className: "json_editor_properties", children: [...missingKeys, ...officialKeys, ...unofficialKeys].map((key) => {
1130
+ const originalKey = stableKeyMap.current[key];
1131
+ const newPath = [...path, key];
1132
+ const originalPath = [...path, originalKey];
1133
+ const isOfficial = schemaKeys === true || schemaKeys.includes(key);
1134
+ const isMissing = missingKeys.includes(key);
1135
+ return isMissing ? /* @__PURE__ */ jsx6(
1136
+ PropertyAdder,
1137
+ {
1138
+ propertyKey: key,
1139
+ addProperty: makePropertyAdder(key, `string`),
1140
+ disabled,
1141
+ Components
1142
+ },
1143
+ key + `IsMissing`
1144
+ ) : /* @__PURE__ */ jsx6(
1145
+ JsonEditor_INTERNAL,
1146
+ {
1147
+ schema,
1148
+ path: newPath,
1149
+ name: key,
1150
+ isReadonly,
1151
+ isHidden,
1152
+ data: data[key],
1153
+ set: setProperty[key],
1154
+ rename: renameProperty[key],
1155
+ remove: removeProperty[key],
1156
+ recast: recastProperty[key],
1157
+ className: `json_editor_property ${isOfficial ? `json_editor_official` : `json_editor_unofficial`}`,
1158
+ Components
1159
+ },
1160
+ originalPath.join(`.`)
1161
+ );
1162
+ }) }),
1163
+ /* @__PURE__ */ jsx6(
1164
+ Components.Button,
1165
+ {
1166
+ onClick: disabled ? doNothing : () => makePropertyAdder(`new_property`, `string`)(),
1167
+ disabled,
1168
+ children: "+"
1169
+ }
1170
+ )
1171
+ ] })
1172
+ ] });
1173
+ };
1174
+
1175
+ // ../../hamr/src/react-json-editor/editors-by-type/primitive-editors.tsx
1176
+ import { jsx as jsx7 } from "@emotion/react/jsx-runtime";
1177
+ var BooleanEditor = ({
1178
+ data,
1179
+ set
1180
+ }) => /* @__PURE__ */ jsx7(
1181
+ "input",
1182
+ {
1183
+ type: "checkbox",
1184
+ checked: data,
1185
+ onChange: (event) => set(event.target.checked)
1186
+ }
1187
+ );
1188
+ var NullEditor = () => /* @__PURE__ */ jsx7("input", { type: "text", value: "null", readOnly: true });
1189
+ var NumberEditor = ({
1190
+ path = [],
1191
+ isReadonly = () => false,
1192
+ data,
1193
+ set
1194
+ }) => /* @__PURE__ */ jsx7(
1195
+ NumberInput,
1196
+ {
1197
+ value: data,
1198
+ set: isReadonly(path) ? void 0 : (newValue) => set(Number(newValue)),
1199
+ autoSize: true
1200
+ }
1201
+ );
1202
+ var StringEditor = ({
1203
+ path = [],
1204
+ isReadonly = () => false,
1205
+ data,
1206
+ set,
1207
+ Components
1208
+ }) => {
1209
+ return /* @__PURE__ */ jsx7(Components.StringWrapper, { children: /* @__PURE__ */ jsx7(
1210
+ TextInput,
1211
+ {
1212
+ value: data,
1213
+ set: isReadonly(path) ? void 0 : set,
1214
+ autoSize: true
1215
+ }
1216
+ ) });
1217
+ };
1218
+
1219
+ // ../../hamr/src/react-error-boundary/ErrorBoundary.tsx
1220
+ import { useId as useId2, Component } from "react";
1221
+ import { atomFamily, useRecoilState, useResetRecoilState } from "recoil";
1222
+
1223
+ // ../../hamr/src/react-error-boundary/DefaultFallback.tsx
1224
+ import { jsx as jsx8, jsxs as jsxs6 } from "@emotion/react/jsx-runtime";
1225
+ var DefaultFallback = ({ error, errorInfo }) => {
1226
+ var _a2, _b;
1227
+ const component = errorInfo == null ? void 0 : errorInfo.componentStack.split(` `).filter(Boolean)[2];
1228
+ const message = (_b = (_a2 = error == null ? void 0 : error.toString()) != null ? _a2 : errorInfo == null ? void 0 : errorInfo.componentStack) != null ? _b : `Unknown error`;
1229
+ return /* @__PURE__ */ jsx8(
1230
+ "div",
1231
+ {
1232
+ "data-testid": "error-boundary",
1233
+ style: {
1234
+ flex: `1`,
1235
+ background: `black`,
1236
+ backgroundImage: `url(./src/assets/kablooey.gif)`,
1237
+ backgroundPosition: `center`,
1238
+ // backgroundRepeat: `no-repeat`,
1239
+ backgroundSize: `overlay`
1240
+ },
1241
+ children: /* @__PURE__ */ jsx8(
1242
+ "div",
1243
+ {
1244
+ style: {
1245
+ margin: `50px`,
1246
+ marginTop: `0`,
1247
+ padding: `50px`,
1248
+ border: `1px solid dashed`
1249
+ },
1250
+ children: /* @__PURE__ */ jsxs6(
1251
+ "span",
1252
+ {
1253
+ style: {
1254
+ background: `black`,
1255
+ color: `white`,
1256
+ padding: 10,
1257
+ paddingTop: 5
1258
+ },
1259
+ children: [
1260
+ `\u26A0\uFE0F `,
1261
+ /* @__PURE__ */ jsx8("span", { style: { color: `#fc0`, fontWeight: 700 }, children: component }),
1262
+ ` \u26A0\uFE0F `,
1263
+ message
1264
+ ]
1265
+ }
1266
+ )
1267
+ }
1268
+ )
1269
+ }
1270
+ );
1271
+ };
1272
+
1273
+ // ../../hamr/src/react-error-boundary/ErrorBoundary.tsx
1274
+ import { jsx as jsx9, jsxs as jsxs7 } from "@emotion/react/jsx-runtime";
1275
+ var ErrorBoundary = class extends Component {
1276
+ constructor(props) {
1277
+ super(props);
1278
+ this.state = { error: void 0, errorInfo: void 0 };
1279
+ }
1280
+ componentDidCatch(error, errorInfo) {
1281
+ var _a2, _b;
1282
+ (_b = (_a2 = this.props).onError) == null ? void 0 : _b.call(_a2, error, errorInfo);
1283
+ this.setState({
1284
+ error,
1285
+ errorInfo
1286
+ });
1287
+ }
1288
+ render() {
1289
+ const { error, errorInfo } = this.state;
1290
+ const { children, Fallback = DefaultFallback } = this.props;
1291
+ return errorInfo ? /* @__PURE__ */ jsx9(Fallback, { error, errorInfo }) : children;
1292
+ }
1293
+ };
1294
+ var findErrorBoundaryState = atomFamily({
1295
+ key: `errorBoundary`,
1296
+ default: { error: void 0, errorInfo: void 0 }
1297
+ });
1298
+
1299
+ // ../../hamr/src/react-json-editor/default-components.tsx
1300
+ import { jsx as jsx10, jsxs as jsxs8 } from "@emotion/react/jsx-runtime";
1301
+ var DEFAULT_JSON_EDITOR_COMPONENTS = {
1302
+ ErrorBoundary: ({ children }) => /* @__PURE__ */ jsx10(ErrorBoundary, { children }),
1303
+ Button: ({ onClick, children, disabled }) => /* @__PURE__ */ jsx10("button", { className: "json_editor_button", onClick, disabled, children }),
1304
+ EditorWrapper: ({ children, customCss, className }) => /* @__PURE__ */ jsx10("div", { className: `json_editor ` + className, css: customCss, children }),
1305
+ EditorLayout: ({
1306
+ DeleteButton,
1307
+ Header,
1308
+ KeyInput,
1309
+ TypeSelect,
1310
+ ValueEditor,
1311
+ Wrapper
1312
+ }) => {
1313
+ return /* @__PURE__ */ jsxs8(Wrapper, { children: [
1314
+ DeleteButton && /* @__PURE__ */ jsx10(DeleteButton, {}),
1315
+ Header && /* @__PURE__ */ jsx10(Header, {}),
1316
+ KeyInput && /* @__PURE__ */ jsx10(KeyInput, {}),
1317
+ TypeSelect && /* @__PURE__ */ jsx10(TypeSelect, {}),
1318
+ /* @__PURE__ */ jsx10(ValueEditor, {})
1319
+ ] });
1320
+ },
1321
+ ArrayWrapper: ({ children }) => /* @__PURE__ */ jsx10("div", { className: "json_editor_array", children }),
1322
+ ObjectWrapper: ({ children }) => /* @__PURE__ */ jsx10("div", { className: "json_editor_object", children }),
1323
+ StringWrapper: ({ children }) => /* @__PURE__ */ jsx10("span", { className: "json_editor_string", children }),
1324
+ NumberWrapper: ({ children }) => /* @__PURE__ */ jsx10("span", { className: "json_editor_number", children }),
1325
+ BooleanWrapper: ({ children }) => /* @__PURE__ */ jsx10("span", { className: "json_editor_boolean", children }),
1326
+ NullWrapper: ({ children }) => /* @__PURE__ */ jsx10("span", { className: "json_editor_null", children }),
1327
+ MissingPropertyWrapper: ({ children }) => /* @__PURE__ */ jsx10("div", { className: "json_editor_property json_editor_missing", children }),
1328
+ MiscastPropertyWrapper: ({ children }) => /* @__PURE__ */ jsx10("div", { className: "json_editor_property json_editor_miscast", children }),
1329
+ IllegalPropertyWrapper: ({ children }) => /* @__PURE__ */ jsx10("span", { className: "json_editor_property json_editor_illegal", children }),
1330
+ OfficialPropertyWrapper: ({ children }) => /* @__PURE__ */ jsx10("span", { className: "json_editor_property json_editor_official", children }),
1331
+ UnofficialPropertyWrapper: ({ children }) => /* @__PURE__ */ jsx10("span", { className: "json_editor_property json_editor_unofficial", children }),
1332
+ DeleteIcon: () => /* @__PURE__ */ jsx10("span", { className: "json_editor_icon json_editor_delete", children: "x" }),
1333
+ KeyWrapper: ({ children }) => /* @__PURE__ */ jsx10("span", { className: "json_editor_key", children })
1334
+ };
1335
+
1336
+ // ../../hamr/src/react-json-editor/developer-interface.tsx
1337
+ import { useMemo } from "react";
1338
+ import Ajv from "ajv";
1339
+ import { jsx as jsx11 } from "@emotion/react/jsx-runtime";
1340
+ var JsonEditor = ({
1341
+ data,
1342
+ set,
1343
+ schema = true,
1344
+ name,
1345
+ rename,
1346
+ remove,
1347
+ isReadonly = () => false,
1348
+ isHidden = () => false,
1349
+ // isIllegal = () => false,
1350
+ className,
1351
+ customCss,
1352
+ Header,
1353
+ Components: CustomComponents = {}
1354
+ }) => {
1355
+ const Components = __spreadValues(__spreadValues({}, DEFAULT_JSON_EDITOR_COMPONENTS), CustomComponents);
1356
+ const ajv = new Ajv({ allErrors: true, verbose: true });
1357
+ const validate = useMemo(() => {
1358
+ return ajv.compile(schema);
1359
+ }, [schema]);
1360
+ const validationResults = validate(data);
1361
+ return /* @__PURE__ */ jsx11(
1362
+ JsonEditor_INTERNAL,
1363
+ {
1364
+ data,
1365
+ set,
1366
+ name,
1367
+ schema,
1368
+ rename,
1369
+ remove,
1370
+ path: [],
1371
+ isReadonly,
1372
+ isHidden,
1373
+ className,
1374
+ customCss,
1375
+ Header,
1376
+ Components
1377
+ }
1378
+ );
1379
+ };
1380
+
1381
+ // ../../hamr/src/react-json-editor/index.ts
1382
+ var SubEditors = {
1383
+ array: ArrayEditor,
1384
+ boolean: BooleanEditor,
1385
+ null: NullEditor,
1386
+ number: NumberEditor,
1387
+ object: ObjectEditor,
1388
+ string: StringEditor
1389
+ };
1390
+
1391
+ // ../src/react-devtools/StateEditor.tsx
1392
+ import { jsx as jsx12 } from "@emotion/react/jsx-runtime";
1393
+ var StateEditor = ({ storeHooks, token }) => {
1394
+ const [data, set] = storeHooks.useIO(token);
1395
+ return isPlainJson(data) ? /* @__PURE__ */ jsx12(JsonEditor, { data, set, schema: true }) : /* @__PURE__ */ jsx12("div", { className: "json_editor", children: /* @__PURE__ */ jsx12(
1396
+ ElasticInput,
1397
+ {
1398
+ value: data instanceof Set ? `Set { ${JSON.stringify([...data]).slice(1, -1)} }` : data instanceof Map ? `Map ` + JSON.stringify([...data]) : Object.getPrototypeOf(data).constructor.name + ` ` + JSON.stringify(data),
1399
+ disabled: true
1400
+ }
1401
+ ) });
1402
+ };
1403
+ var ReadonlySelectorEditor = ({ storeHooks, token }) => {
1404
+ const data = storeHooks.useO(token);
1405
+ return isPlainJson(data) ? /* @__PURE__ */ jsx12(
1406
+ JsonEditor,
1407
+ {
1408
+ data,
1409
+ set: () => null,
1410
+ schema: true,
1411
+ isReadonly: () => true
1412
+ }
1413
+ ) : /* @__PURE__ */ jsx12("div", { className: "json_editor", children: /* @__PURE__ */ jsx12(
1414
+ ElasticInput,
1415
+ {
1416
+ value: data instanceof Set ? `Set ` + JSON.stringify([...data]) : data instanceof Map ? `Map ` + JSON.stringify([...data]) : Object.getPrototypeOf(data).constructor.name + ` ` + JSON.stringify(data),
1417
+ disabled: true
1418
+ }
1419
+ ) });
1420
+ };
1421
+ var StoreEditor = ({ storeHooks, token }) => {
1422
+ if (token.type === `readonly_selector`) {
1423
+ return /* @__PURE__ */ jsx12(ReadonlySelectorEditor, { storeHooks, token });
1424
+ }
1425
+ return /* @__PURE__ */ jsx12(StateEditor, { storeHooks, token });
1426
+ };
1427
+
1428
+ // ../src/react-devtools/TokenList.tsx
1429
+ import { Fragment as Fragment4, jsx as jsx13, jsxs as jsxs9 } from "@emotion/react/jsx-runtime";
1430
+ var TokenList = ({ storeHooks, tokenIndex }) => {
1431
+ const tokenIds = storeHooks.useO(tokenIndex);
1432
+ return /* @__PURE__ */ jsx13(Fragment4, { children: Object.entries(tokenIds).map(([key, token]) => /* @__PURE__ */ jsx13(Fragment3, { children: key.startsWith(`\u{1F441}\u200D\u{1F5E8}_`) ? null : /* @__PURE__ */ jsxs9("div", { className: "node", children: [
1433
+ key,
1434
+ ":",
1435
+ `type` in token ? /* @__PURE__ */ jsx13(StoreEditor, { storeHooks, token }) : recordToEntries(token.familyMembers).map(([key2, token2]) => /* @__PURE__ */ jsxs9("div", { className: "node", children: [
1436
+ key2,
1437
+ ":",
1438
+ /* @__PURE__ */ jsx13(StoreEditor, { storeHooks, token: token2 })
1439
+ ] }, key2))
1440
+ ] }) }, key)) });
1441
+ };
1442
+
1443
+ // ../src/web-effects/storage.ts
1444
+ var persistAtom = (storage) => ({ stringify, parse }) => (key) => ({ setSelf, onSet }) => {
1445
+ const savedValue = storage.getItem(key);
1446
+ if (savedValue != null)
1447
+ setSelf(parse(savedValue));
1448
+ onSet(({ newValue }) => {
1449
+ if (newValue == null) {
1450
+ storage.removeItem(key);
1451
+ return;
1452
+ }
1453
+ storage.setItem(key, stringify(newValue));
1454
+ });
1455
+ };
1456
+ var lazyLocalStorageEffect = persistAtom(localStorage)(JSON);
1457
+
1458
+ // ../src/react-devtools/AtomIODevtools.tsx
1459
+ import { Fragment as Fragment5, jsx as jsx14, jsxs as jsxs10 } from "@emotion/react/jsx-runtime";
1460
+ var { atomTokenIndexState, selectorTokenIndexState } = __INTERNAL__.META.attachMetaState();
1461
+ var devtoolsAreOpenState = atom({
1462
+ key: `\u{1F441}\u200D\u{1F5E8}_devtools_are_open`,
1463
+ default: true,
1464
+ effects: [lazyLocalStorageEffect(`\u{1F441}\u200D\u{1F5E8}_devtools_are_open`)]
1465
+ });
1466
+ var composeDevtools = (storeHooks) => {
1467
+ const Devtools = () => {
1468
+ const constraintsRef = useRef4(null);
1469
+ const [devtoolsAreOpen, setDevtoolsAreOpen] = storeHooks.useIO(devtoolsAreOpenState);
1470
+ const mouseHasMoved = useRef4(false);
1471
+ return /* @__PURE__ */ jsxs10(Fragment5, { children: [
1472
+ /* @__PURE__ */ jsx14(
1473
+ motion.span,
1474
+ {
1475
+ ref: constraintsRef,
1476
+ className: "atom_io_devtools_zone",
1477
+ style: {
1478
+ position: `fixed`,
1479
+ top: 0,
1480
+ left: 0,
1481
+ right: 0,
1482
+ bottom: 0,
1483
+ pointerEvents: `none`
1484
+ }
1485
+ }
1486
+ ),
1487
+ /* @__PURE__ */ jsxs10(
1488
+ motion.main,
1489
+ {
1490
+ drag: true,
1491
+ dragConstraints: constraintsRef,
1492
+ className: "atom_io_devtools",
1493
+ transition: spring,
1494
+ style: devtoolsAreOpen ? {} : {
1495
+ backgroundColor: `#0000`,
1496
+ borderColor: `#0000`,
1497
+ maxHeight: 28,
1498
+ maxWidth: 33
1499
+ },
1500
+ children: [
1501
+ devtoolsAreOpen ? /* @__PURE__ */ jsxs10(Fragment5, { children: [
1502
+ /* @__PURE__ */ jsx14(motion.header, { children: /* @__PURE__ */ jsx14("h1", { children: "atom.io" }) }),
1503
+ /* @__PURE__ */ jsx14(motion.main, { children: /* @__PURE__ */ jsxs10(LayoutGroup, { children: [
1504
+ /* @__PURE__ */ jsxs10("section", { children: [
1505
+ /* @__PURE__ */ jsx14("h2", { children: "atoms" }),
1506
+ /* @__PURE__ */ jsx14(
1507
+ TokenList,
1508
+ {
1509
+ storeHooks,
1510
+ tokenIndex: atomTokenIndexState
1511
+ }
1512
+ )
1513
+ ] }),
1514
+ /* @__PURE__ */ jsxs10("section", { children: [
1515
+ /* @__PURE__ */ jsx14("h2", { children: "selectors" }),
1516
+ /* @__PURE__ */ jsx14(
1517
+ TokenList,
1518
+ {
1519
+ storeHooks,
1520
+ tokenIndex: selectorTokenIndexState
1521
+ }
1522
+ )
1523
+ ] })
1524
+ ] }) })
1525
+ ] }) : null,
1526
+ /* @__PURE__ */ jsx14("footer", { children: /* @__PURE__ */ jsx14(
1527
+ "button",
1528
+ {
1529
+ onMouseDown: () => mouseHasMoved.current = false,
1530
+ onMouseMove: () => mouseHasMoved.current = true,
1531
+ onMouseUp: () => {
1532
+ if (!mouseHasMoved.current) {
1533
+ setDevtoolsAreOpen((open) => !open);
1534
+ }
1535
+ },
1536
+ children: "\u{1F441}\u200D\u{1F5E8}"
1537
+ }
1538
+ ) })
1539
+ ]
1540
+ }
1541
+ )
1542
+ ] });
1543
+ };
1544
+ return Devtools;
1545
+ };
1546
+ var AtomIODevtools = composeDevtools({ useI, useO, useIO });
1547
+ export {
1548
+ AtomIODevtools,
1549
+ composeDevtools
1550
+ };
1551
+ //# sourceMappingURL=index.mjs.map