@buoy-gg/storage 7.0.4 → 7.0.5

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 (148) hide show
  1. package/lib/commonjs/index.js +77 -1
  2. package/lib/commonjs/storage/components/DiffViewer/TreeDiffViewer.js +10 -3
  3. package/lib/commonjs/storage/components/DiffViewer/modes/ThemedSplitView.js +26 -8
  4. package/lib/commonjs/storage/components/GameUIStorageBrowser.js +263 -115
  5. package/lib/commonjs/storage/components/GameUIStorageStats.js +7 -7
  6. package/lib/commonjs/storage/components/MMKVInstanceInfoPanel.js +1 -1
  7. package/lib/commonjs/storage/components/MMKVInstanceSelector.js +1 -1
  8. package/lib/commonjs/storage/components/SelectionActionBar.js +2 -36
  9. package/lib/commonjs/storage/components/StorageActions.js +6 -6
  10. package/lib/commonjs/storage/components/StorageBrowserMode.js +16 -2
  11. package/lib/commonjs/storage/components/StorageEventDetailContent.js +106 -149
  12. package/lib/commonjs/storage/components/StorageEventListener.js +13 -13
  13. package/lib/commonjs/storage/components/StorageFilterCards.js +13 -135
  14. package/lib/commonjs/storage/components/StorageKeyCard.js +1 -1
  15. package/lib/commonjs/storage/components/StorageKeyEditorScreen.js +392 -0
  16. package/lib/commonjs/storage/components/StorageKeyRow.js +53 -15
  17. package/lib/commonjs/storage/components/StorageKeySection.js +10 -4
  18. package/lib/commonjs/storage/components/StorageKeyStats.js +10 -10
  19. package/lib/commonjs/storage/components/StorageModalWithTabs.js +272 -129
  20. package/lib/commonjs/storage/components/StorageScalarKeyEditor.js +46 -0
  21. package/lib/commonjs/storage/components/StorageTypeFilterBar.js +141 -0
  22. package/lib/commonjs/storage/components/StorageValueEditModal.js +361 -0
  23. package/lib/commonjs/storage/hooks/useKeyEditor.js +104 -0
  24. package/lib/commonjs/storage/hooks/useMeasuredWidth.js +74 -0
  25. package/lib/commonjs/storage/hooks/useSecureStoreKeys.js +70 -15
  26. package/lib/commonjs/storage/hooks/useTreeDraft.js +107 -0
  27. package/lib/commonjs/storage/index.js +29 -0
  28. package/lib/commonjs/storage/stores/storageEventStore.js +4 -2
  29. package/lib/commonjs/storage/sync/storageSyncAdapter.js +125 -3
  30. package/lib/commonjs/storage/utils/AsyncStorageListener.js +76 -12
  31. package/lib/commonjs/storage/utils/MMKVInstanceRegistry.js +10 -9
  32. package/lib/commonjs/storage/utils/MMKVListener.js +40 -4
  33. package/lib/commonjs/storage/utils/SecureStoreRegistry.js +52 -1
  34. package/lib/commonjs/storage/utils/deleteStorageKeys.js +53 -0
  35. package/lib/commonjs/storage/utils/index.js +13 -0
  36. package/lib/commonjs/storage/utils/lineDiff.js +21 -354
  37. package/lib/commonjs/storage/utils/setStorageValue.js +218 -0
  38. package/lib/commonjs/storage/utils/storageBrowserRefresh.js +49 -0
  39. package/lib/commonjs/storage/utils/storageOps.js +53 -0
  40. package/lib/commonjs/storage/utils/storageTimeTravelUtils.js +60 -38
  41. package/lib/commonjs/storage/utils/valueType.js +24 -0
  42. package/lib/module/index.js +18 -1
  43. package/lib/module/storage/components/DiffViewer/TreeDiffViewer.js +10 -3
  44. package/lib/module/storage/components/DiffViewer/modes/ThemedSplitView.js +26 -8
  45. package/lib/module/storage/components/GameUIStorageBrowser.js +266 -118
  46. package/lib/module/storage/components/GameUIStorageStats.js +7 -7
  47. package/lib/module/storage/components/MMKVInstanceInfoPanel.js +1 -1
  48. package/lib/module/storage/components/MMKVInstanceSelector.js +1 -1
  49. package/lib/module/storage/components/SelectionActionBar.js +2 -36
  50. package/lib/module/storage/components/StorageActions.js +7 -7
  51. package/lib/module/storage/components/StorageBrowserMode.js +16 -2
  52. package/lib/module/storage/components/StorageEventDetailContent.js +110 -151
  53. package/lib/module/storage/components/StorageEventListener.js +14 -14
  54. package/lib/module/storage/components/StorageFilterCards.js +13 -135
  55. package/lib/module/storage/components/StorageKeyCard.js +1 -1
  56. package/lib/module/storage/components/StorageKeyEditorScreen.js +388 -0
  57. package/lib/module/storage/components/StorageKeyRow.js +55 -17
  58. package/lib/module/storage/components/StorageKeySection.js +11 -5
  59. package/lib/module/storage/components/StorageKeyStats.js +11 -10
  60. package/lib/module/storage/components/StorageModalWithTabs.js +272 -130
  61. package/lib/module/storage/components/StorageScalarKeyEditor.js +42 -0
  62. package/lib/module/storage/components/StorageTypeFilterBar.js +136 -0
  63. package/lib/module/storage/components/StorageValueEditModal.js +357 -0
  64. package/lib/module/storage/hooks/useKeyEditor.js +100 -0
  65. package/lib/module/storage/hooks/useMeasuredWidth.js +71 -0
  66. package/lib/module/storage/hooks/useSecureStoreKeys.js +71 -16
  67. package/lib/module/storage/hooks/useTreeDraft.js +103 -0
  68. package/lib/module/storage/index.js +3 -0
  69. package/lib/module/storage/stores/storageEventStore.js +4 -2
  70. package/lib/module/storage/sync/storageSyncAdapter.js +125 -3
  71. package/lib/module/storage/utils/AsyncStorageListener.js +76 -12
  72. package/lib/module/storage/utils/MMKVInstanceRegistry.js +8 -7
  73. package/lib/module/storage/utils/MMKVListener.js +40 -4
  74. package/lib/module/storage/utils/SecureStoreRegistry.js +52 -1
  75. package/lib/module/storage/utils/deleteStorageKeys.js +49 -0
  76. package/lib/module/storage/utils/index.js +3 -0
  77. package/lib/module/storage/utils/lineDiff.js +7 -354
  78. package/lib/module/storage/utils/setStorageValue.js +209 -0
  79. package/lib/module/storage/utils/storageBrowserRefresh.js +44 -0
  80. package/lib/module/storage/utils/storageOps.js +46 -0
  81. package/lib/module/storage/utils/storageTimeTravelUtils.js +61 -40
  82. package/lib/module/storage/utils/valueType.js +23 -0
  83. package/lib/typescript/index.d.ts +12 -1
  84. package/lib/typescript/index.d.ts.map +1 -1
  85. package/lib/typescript/storage/components/DiffViewer/TreeDiffViewer.d.ts +4 -1
  86. package/lib/typescript/storage/components/DiffViewer/TreeDiffViewer.d.ts.map +1 -1
  87. package/lib/typescript/storage/components/DiffViewer/modes/ThemedSplitView.d.ts +7 -1
  88. package/lib/typescript/storage/components/DiffViewer/modes/ThemedSplitView.d.ts.map +1 -1
  89. package/lib/typescript/storage/components/GameUIStorageBrowser.d.ts +27 -1
  90. package/lib/typescript/storage/components/GameUIStorageBrowser.d.ts.map +1 -1
  91. package/lib/typescript/storage/components/SelectionActionBar.d.ts.map +1 -1
  92. package/lib/typescript/storage/components/StorageBrowserMode.d.ts +17 -1
  93. package/lib/typescript/storage/components/StorageBrowserMode.d.ts.map +1 -1
  94. package/lib/typescript/storage/components/StorageEventDetailContent.d.ts +4 -1
  95. package/lib/typescript/storage/components/StorageEventDetailContent.d.ts.map +1 -1
  96. package/lib/typescript/storage/components/StorageFilterCards.d.ts +9 -3
  97. package/lib/typescript/storage/components/StorageFilterCards.d.ts.map +1 -1
  98. package/lib/typescript/storage/components/StorageKeyEditorScreen.d.ts +42 -0
  99. package/lib/typescript/storage/components/StorageKeyEditorScreen.d.ts.map +1 -0
  100. package/lib/typescript/storage/components/StorageKeyRow.d.ts +17 -0
  101. package/lib/typescript/storage/components/StorageKeyRow.d.ts.map +1 -1
  102. package/lib/typescript/storage/components/StorageKeySection.d.ts +7 -1
  103. package/lib/typescript/storage/components/StorageKeySection.d.ts.map +1 -1
  104. package/lib/typescript/storage/components/StorageKeyStats.d.ts.map +1 -1
  105. package/lib/typescript/storage/components/StorageModalWithTabs.d.ts +28 -1
  106. package/lib/typescript/storage/components/StorageModalWithTabs.d.ts.map +1 -1
  107. package/lib/typescript/storage/components/StorageScalarKeyEditor.d.ts +24 -0
  108. package/lib/typescript/storage/components/StorageScalarKeyEditor.d.ts.map +1 -0
  109. package/lib/typescript/storage/components/StorageTypeFilterBar.d.ts +29 -0
  110. package/lib/typescript/storage/components/StorageTypeFilterBar.d.ts.map +1 -0
  111. package/lib/typescript/storage/components/StorageValueEditModal.d.ts +36 -0
  112. package/lib/typescript/storage/components/StorageValueEditModal.d.ts.map +1 -0
  113. package/lib/typescript/storage/hooks/useKeyEditor.d.ts +51 -0
  114. package/lib/typescript/storage/hooks/useKeyEditor.d.ts.map +1 -0
  115. package/lib/typescript/storage/hooks/useMeasuredWidth.d.ts +37 -0
  116. package/lib/typescript/storage/hooks/useMeasuredWidth.d.ts.map +1 -0
  117. package/lib/typescript/storage/hooks/useSecureStoreKeys.d.ts +8 -1
  118. package/lib/typescript/storage/hooks/useSecureStoreKeys.d.ts.map +1 -1
  119. package/lib/typescript/storage/hooks/useTreeDraft.d.ts +67 -0
  120. package/lib/typescript/storage/hooks/useTreeDraft.d.ts.map +1 -0
  121. package/lib/typescript/storage/index.d.ts +2 -0
  122. package/lib/typescript/storage/index.d.ts.map +1 -1
  123. package/lib/typescript/storage/sync/storageSyncAdapter.d.ts +41 -0
  124. package/lib/typescript/storage/sync/storageSyncAdapter.d.ts.map +1 -1
  125. package/lib/typescript/storage/utils/AsyncStorageListener.d.ts +15 -0
  126. package/lib/typescript/storage/utils/AsyncStorageListener.d.ts.map +1 -1
  127. package/lib/typescript/storage/utils/MMKVInstanceRegistry.d.ts.map +1 -1
  128. package/lib/typescript/storage/utils/MMKVListener.d.ts +7 -0
  129. package/lib/typescript/storage/utils/MMKVListener.d.ts.map +1 -1
  130. package/lib/typescript/storage/utils/SecureStoreRegistry.d.ts +20 -0
  131. package/lib/typescript/storage/utils/SecureStoreRegistry.d.ts.map +1 -1
  132. package/lib/typescript/storage/utils/deleteStorageKeys.d.ts +27 -0
  133. package/lib/typescript/storage/utils/deleteStorageKeys.d.ts.map +1 -0
  134. package/lib/typescript/storage/utils/index.d.ts +1 -0
  135. package/lib/typescript/storage/utils/index.d.ts.map +1 -1
  136. package/lib/typescript/storage/utils/lineDiff.d.ts +7 -31
  137. package/lib/typescript/storage/utils/lineDiff.d.ts.map +1 -1
  138. package/lib/typescript/storage/utils/setStorageValue.d.ts +64 -0
  139. package/lib/typescript/storage/utils/setStorageValue.d.ts.map +1 -0
  140. package/lib/typescript/storage/utils/storageBrowserRefresh.d.ts +28 -0
  141. package/lib/typescript/storage/utils/storageBrowserRefresh.d.ts.map +1 -0
  142. package/lib/typescript/storage/utils/storageOps.d.ts +25 -0
  143. package/lib/typescript/storage/utils/storageOps.d.ts.map +1 -0
  144. package/lib/typescript/storage/utils/storageTimeTravelUtils.d.ts +15 -5
  145. package/lib/typescript/storage/utils/storageTimeTravelUtils.d.ts.map +1 -1
  146. package/lib/typescript/storage/utils/valueType.d.ts +13 -0
  147. package/lib/typescript/storage/utils/valueType.d.ts.map +1 -1
  148. package/package.json +5 -5
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * "Which backend?" — the pill row shared by the Keys and Events tabs.
5
+ *
6
+ * Both tabs answer questions about the same three backends, so asking the
7
+ * question two different ways (or, as it was, only on one tab) is a gap rather
8
+ * than a simplification: you filter the key list to Keychain, switch to Events
9
+ * to see what wrote to it, and you're looking at everything again.
10
+ *
11
+ * The selection is owned by the modal and passed to both, so switching tabs
12
+ * keeps the filter you set.
13
+ *
14
+ * Each pill carries the count it WOULD show, computed before the type filter is
15
+ * applied — a count that collapsed to zero the moment you picked another type
16
+ * would tell you nothing about where to look next.
17
+ */
18
+
19
+ import { StyleSheet, Text, TouchableOpacity, View } from "react-native";
20
+ import { macOSColors } from "@buoy-gg/shared-ui";
21
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
22
+ /**
23
+ * One entry per pill. This was four near-identical blocks of JSX differing only
24
+ * in three colours and a label, which is how "All Types" ended up with a
25
+ * hover-grey active state while the others used their own hue.
26
+ */
27
+ const SEGMENTS = [{
28
+ id: "all",
29
+ label: "All Types",
30
+ color: null
31
+ }, {
32
+ id: "async",
33
+ label: "Async",
34
+ color: macOSColors.semantic.warning
35
+ }, {
36
+ id: "mmkv",
37
+ label: "MMKV",
38
+ color: macOSColors.semantic.info
39
+ }, {
40
+ id: "secure",
41
+ label: "Secure",
42
+ color: macOSColors.semantic.success
43
+ }];
44
+ export function StorageTypeFilterBar({
45
+ active,
46
+ onChange,
47
+ counts
48
+ }) {
49
+ return /*#__PURE__*/_jsx(View, {
50
+ style: styles.row,
51
+ children: SEGMENTS.map(segment => {
52
+ const isActive = active === segment.id;
53
+ const accent = segment.color ?? macOSColors.text.primary;
54
+ return /*#__PURE__*/_jsxs(TouchableOpacity, {
55
+ accessibilityLabel: `Filter by ${segment.label}`,
56
+ accessibilityState: {
57
+ selected: isActive
58
+ },
59
+ activeOpacity: 0.8,
60
+ onPress: () => onChange(segment.id),
61
+ style: [styles.pill, {
62
+ borderColor: macOSColors.border.default
63
+ }, isActive && [styles.pillActive, segment.color ? {
64
+ backgroundColor: segment.color + "15",
65
+ borderColor: segment.color + "40"
66
+ } : {
67
+ backgroundColor: macOSColors.background.hover,
68
+ borderColor: macOSColors.border.hover
69
+ }]],
70
+ children: [/*#__PURE__*/_jsx(Text, {
71
+ style: [styles.label, isActive && {
72
+ color: accent,
73
+ fontWeight: "600"
74
+ }],
75
+ children: segment.label
76
+ }), /*#__PURE__*/_jsx(Text, {
77
+ style: [styles.value, {
78
+ color: isActive ? accent : macOSColors.text.muted
79
+ }],
80
+ children: counts[segment.id]
81
+ })]
82
+ }, segment.id);
83
+ })
84
+ });
85
+ }
86
+
87
+ /** Tally a list of things that each know which backend they came from. */
88
+ export function countByStorageType(items) {
89
+ const counts = {
90
+ all: items.length,
91
+ async: 0,
92
+ mmkv: 0,
93
+ secure: 0
94
+ };
95
+ for (const item of items) counts[item.storageType] += 1;
96
+ return counts;
97
+ }
98
+ const styles = StyleSheet.create({
99
+ row: {
100
+ flexDirection: "row",
101
+ gap: 8,
102
+ marginTop: 2
103
+ },
104
+ pill: {
105
+ flex: 1,
106
+ backgroundColor: macOSColors.background.input + "80",
107
+ borderRadius: 8,
108
+ borderWidth: 1,
109
+ borderColor: macOSColors.border.default + "30",
110
+ paddingVertical: 6,
111
+ paddingHorizontal: 8,
112
+ alignItems: "center",
113
+ justifyContent: "center",
114
+ minHeight: 32
115
+ },
116
+ pillActive: {
117
+ borderWidth: 1,
118
+ transform: [{
119
+ scale: 1.005
120
+ }]
121
+ },
122
+ label: {
123
+ fontSize: 9,
124
+ color: macOSColors.text.secondary,
125
+ textTransform: "uppercase",
126
+ letterSpacing: 0.4,
127
+ fontWeight: "500",
128
+ marginBottom: 1
129
+ },
130
+ value: {
131
+ fontSize: 12,
132
+ fontWeight: "600",
133
+ fontFamily: "monospace",
134
+ lineHeight: 14
135
+ }
136
+ });
@@ -0,0 +1,357 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Editing one value: a panel at the top of the screen, with Cancel and Save.
5
+ *
6
+ * This started as a pushed full screen and that was more ceremony than the task
7
+ * deserves — changing one string is the most ordinary thing in this tool, and
8
+ * it shouldn't cost a navigation. A modal is what people expect, and the reason
9
+ * it's pinned to the TOP rather than centred is the keyboard: a centred panel
10
+ * gets shoved up or covered the moment the field focuses, and a bottom sheet is
11
+ * simply underneath it. At the top it stays put and stays readable.
12
+ *
13
+ * The field is multiline for anything textual. Stored values are routinely
14
+ * tokens, URLs and serialized blobs, and a single line shows you roughly forty
15
+ * characters of them, scrolling sideways — which is how you edit the wrong part
16
+ * of a string without noticing.
17
+ *
18
+ * Type is preserved by construction: the ORIGINAL value's type picks the editor
19
+ * AND decides how the draft is read back, so editing a number can only produce
20
+ * a number. Raw JSON — the escape hatch for containers — re-checks the parsed
21
+ * result and refuses a different shape.
22
+ *
23
+ * Nothing here writes. `onSave` hands the value to whoever owns it.
24
+ */
25
+
26
+ import { useState } from "react";
27
+ import { ScrollView, StyleSheet, Text, TextInput, TouchableOpacity, View } from "react-native";
28
+ import { absoluteFill, macOSColors } from "@buoy-gg/shared-ui";
29
+ import { breadcrumb, typeLabel } from "@buoy-gg/shared-ui/dataViewer";
30
+
31
+ /**
32
+ * How this value gets edited. Driven by the value's own type, which is also
33
+ * what makes the result type-safe without asking the user to declare anything.
34
+ */
35
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
36
+ function modeFor(value) {
37
+ if (typeof value === "boolean") return "boolean";
38
+ if (typeof value === "number") return "number";
39
+ if (value !== null && typeof value === "object") return "raw";
40
+ return "text";
41
+ }
42
+ function initialText(value, mode) {
43
+ if (mode === "raw") return JSON.stringify(value, null, 2);
44
+ if (value === null || value === undefined) return "";
45
+ return String(value);
46
+ }
47
+ function hintFor(mode, type) {
48
+ switch (mode) {
49
+ case "number":
50
+ return "Numeric only — anything else is refused, so this stays a number.";
51
+ case "raw":
52
+ return `Raw JSON. Must stay ${type === "array" ? "an array" : "an object"} — a different shape is refused.`;
53
+ default:
54
+ return "Saves as a string. The type never changes here.";
55
+ }
56
+ }
57
+ export function StorageValueEditModal({
58
+ path,
59
+ value,
60
+ onSave,
61
+ onCancel,
62
+ saveLabel = "Save",
63
+ busy = false
64
+ }) {
65
+ const mode = modeFor(value);
66
+ const type = typeLabel(value);
67
+ const [text, setText] = useState(() => initialText(value, mode));
68
+
69
+ /**
70
+ * Advisory only — {@link commit} re-derives it, so a disabled button and a
71
+ * refused save can never disagree about what's valid.
72
+ */
73
+ const error = validate(text, mode, type);
74
+ const blocked = busy || error != null;
75
+ const commit = () => {
76
+ if (busy || validate(text, mode, type) != null) return;
77
+ onSave(parse(text, mode, value));
78
+ };
79
+ return /*#__PURE__*/_jsxs(View, {
80
+ style: styles.overlay,
81
+ children: [/*#__PURE__*/_jsx(TouchableOpacity, {
82
+ style: styles.scrim,
83
+ activeOpacity: 1,
84
+ onPress: busy ? undefined : onCancel,
85
+ accessibilityLabel: "Dismiss editor"
86
+ }), /*#__PURE__*/_jsx(View, {
87
+ style: styles.panel,
88
+ pointerEvents: "box-none",
89
+ children: /*#__PURE__*/_jsxs(View, {
90
+ style: styles.card,
91
+ children: [/*#__PURE__*/_jsxs(View, {
92
+ style: styles.headerRow,
93
+ children: [/*#__PURE__*/_jsx(Text, {
94
+ style: styles.title,
95
+ children: "Edit value"
96
+ }), /*#__PURE__*/_jsx(View, {
97
+ style: styles.typeBadge,
98
+ children: /*#__PURE__*/_jsx(Text, {
99
+ style: styles.typeBadgeText,
100
+ children: type
101
+ })
102
+ })]
103
+ }), /*#__PURE__*/_jsx(Text, {
104
+ style: styles.path,
105
+ numberOfLines: 1,
106
+ children: breadcrumb(path)
107
+ }), mode === "boolean" ? /*#__PURE__*/_jsx(BooleanChoice, {
108
+ current: value === true,
109
+ onPick: onSave
110
+ }) : /*#__PURE__*/_jsx(ScrollView, {
111
+ style: styles.fieldScroll,
112
+ keyboardShouldPersistTaps: "handled",
113
+ children: /*#__PURE__*/_jsx(TextInput, {
114
+ value: text,
115
+ onChangeText: setText,
116
+ autoFocus: true,
117
+ autoCapitalize: "none",
118
+ autoCorrect: false,
119
+ spellCheck: false,
120
+ editable: !busy
121
+ // Multiline for anything textual: stored values are long more
122
+ // often than they're short, and a single line hides that.
123
+ ,
124
+ multiline: mode !== "number",
125
+ keyboardType: mode === "number" ? "numeric" : "default",
126
+ onSubmitEditing: mode === "number" ? commit : undefined,
127
+ placeholder: mode === "raw" ? "{ }" : "value",
128
+ placeholderTextColor: macOSColors.text.muted,
129
+ style: [styles.input, mode === "raw" && styles.inputRaw, mode !== "number" && styles.inputMultiline, error != null && styles.inputInvalid]
130
+ })
131
+ }), /*#__PURE__*/_jsx(Text, {
132
+ style: error != null ? styles.error : styles.hint,
133
+ children: error ?? hintFor(mode, type)
134
+ }), /*#__PURE__*/_jsxs(View, {
135
+ style: styles.actions,
136
+ children: [/*#__PURE__*/_jsx(TouchableOpacity, {
137
+ onPress: onCancel,
138
+ disabled: busy,
139
+ accessibilityLabel: "Cancel edit",
140
+ style: styles.cancelButton,
141
+ children: /*#__PURE__*/_jsx(Text, {
142
+ style: styles.cancelText,
143
+ children: "Cancel"
144
+ })
145
+ }), mode === "boolean" ? null : /*#__PURE__*/_jsx(TouchableOpacity, {
146
+ onPress: commit,
147
+ disabled: blocked,
148
+ accessibilityLabel: saveLabel,
149
+ style: [styles.saveButton, blocked && styles.saveDisabled],
150
+ children: /*#__PURE__*/_jsx(Text, {
151
+ style: styles.saveText,
152
+ children: busy ? "Saving…" : saveLabel
153
+ })
154
+ })]
155
+ })]
156
+ })
157
+ })]
158
+ });
159
+ }
160
+ function BooleanChoice({
161
+ current,
162
+ onPick
163
+ }) {
164
+ return /*#__PURE__*/_jsx(View, {
165
+ style: styles.boolRow,
166
+ children: [true, false].map(option => /*#__PURE__*/_jsx(TouchableOpacity, {
167
+ onPress: () => onPick(option),
168
+ accessibilityLabel: `Set ${option}`,
169
+ style: [styles.boolButton, current === option && styles.boolActive],
170
+ children: /*#__PURE__*/_jsx(Text, {
171
+ style: [styles.boolText, current === option && styles.boolTextActive],
172
+ children: String(option)
173
+ })
174
+ }, String(option)))
175
+ });
176
+ }
177
+
178
+ /** Null when the draft is applicable, else why it isn't. */
179
+ function validate(text, mode, type) {
180
+ if (mode === "number") {
181
+ if (text.trim() === "") return "Enter a number.";
182
+ if (Number.isNaN(Number(text))) return `"${text}" isn't a number.`;
183
+ return null;
184
+ }
185
+ if (mode === "raw") {
186
+ let parsed;
187
+ try {
188
+ parsed = JSON.parse(text);
189
+ } catch (e) {
190
+ return e instanceof Error ? e.message : "Invalid JSON.";
191
+ }
192
+ if (typeLabel(parsed) !== type) {
193
+ return `Must stay ${type} — that parses as ${typeLabel(parsed)}.`;
194
+ }
195
+ return null;
196
+ }
197
+ return null;
198
+ }
199
+ function parse(text, mode, original) {
200
+ if (mode === "number") return Number(text);
201
+ if (mode === "raw") return JSON.parse(text);
202
+ // An emptied field on a null keeps it null rather than silently minting an
203
+ // empty string, which would change the type this promised to preserve.
204
+ if (original === null && text === "") return null;
205
+ return text;
206
+ }
207
+ const styles = StyleSheet.create({
208
+ overlay: {
209
+ ...absoluteFill,
210
+ zIndex: 20
211
+ },
212
+ scrim: {
213
+ ...absoluteFill,
214
+ backgroundColor: "rgba(0,0,0,0.55)"
215
+ },
216
+ /** Pinned to the top so the keyboard can't reach it. */
217
+ panel: {
218
+ padding: 12
219
+ },
220
+ card: {
221
+ backgroundColor: macOSColors.background.card,
222
+ borderRadius: 14,
223
+ borderWidth: 1,
224
+ borderColor: macOSColors.border.default,
225
+ padding: 14,
226
+ gap: 8
227
+ },
228
+ headerRow: {
229
+ flexDirection: "row",
230
+ alignItems: "center",
231
+ gap: 8
232
+ },
233
+ title: {
234
+ flex: 1,
235
+ color: macOSColors.text.primary,
236
+ fontSize: 14,
237
+ fontWeight: "700"
238
+ },
239
+ typeBadge: {
240
+ paddingHorizontal: 8,
241
+ paddingVertical: 2,
242
+ borderRadius: 6,
243
+ backgroundColor: macOSColors.background.hover
244
+ },
245
+ typeBadgeText: {
246
+ color: macOSColors.semantic.warning,
247
+ fontSize: 10,
248
+ fontWeight: "700",
249
+ fontFamily: "monospace"
250
+ },
251
+ path: {
252
+ color: macOSColors.text.muted,
253
+ fontSize: 11,
254
+ fontFamily: "monospace"
255
+ },
256
+ /** Caps the panel's height so a huge blob can't push the buttons off-screen. */
257
+ fieldScroll: {
258
+ maxHeight: 240
259
+ },
260
+ input: {
261
+ color: macOSColors.text.primary,
262
+ backgroundColor: macOSColors.background.input,
263
+ borderWidth: 1,
264
+ borderColor: macOSColors.border.input,
265
+ borderRadius: 10,
266
+ paddingHorizontal: 12,
267
+ paddingVertical: 10,
268
+ fontSize: 14,
269
+ fontFamily: "monospace"
270
+ },
271
+ inputMultiline: {
272
+ minHeight: 110,
273
+ lineHeight: 20,
274
+ textAlignVertical: "top"
275
+ },
276
+ inputRaw: {
277
+ minHeight: 180,
278
+ fontSize: 12,
279
+ lineHeight: 18
280
+ },
281
+ inputInvalid: {
282
+ borderColor: macOSColors.semantic.error
283
+ },
284
+ hint: {
285
+ color: macOSColors.text.muted,
286
+ fontSize: 11,
287
+ lineHeight: 16
288
+ },
289
+ error: {
290
+ color: macOSColors.semantic.error,
291
+ fontSize: 11,
292
+ lineHeight: 16,
293
+ fontFamily: "monospace"
294
+ },
295
+ actions: {
296
+ flexDirection: "row",
297
+ gap: 8,
298
+ paddingTop: 2
299
+ },
300
+ cancelButton: {
301
+ flex: 1,
302
+ minHeight: 44,
303
+ alignItems: "center",
304
+ justifyContent: "center",
305
+ borderRadius: 10,
306
+ borderWidth: 1,
307
+ borderColor: macOSColors.border.default
308
+ },
309
+ cancelText: {
310
+ color: macOSColors.text.secondary,
311
+ fontSize: 14,
312
+ fontWeight: "600"
313
+ },
314
+ saveButton: {
315
+ flex: 1.4,
316
+ minHeight: 44,
317
+ alignItems: "center",
318
+ justifyContent: "center",
319
+ borderRadius: 10,
320
+ backgroundColor: macOSColors.semantic.success
321
+ },
322
+ saveDisabled: {
323
+ opacity: 0.35
324
+ },
325
+ saveText: {
326
+ color: macOSColors.background.base,
327
+ fontSize: 15,
328
+ fontWeight: "700"
329
+ },
330
+ boolRow: {
331
+ flexDirection: "row",
332
+ gap: 10
333
+ },
334
+ boolButton: {
335
+ flex: 1,
336
+ minHeight: 64,
337
+ alignItems: "center",
338
+ justifyContent: "center",
339
+ borderRadius: 12,
340
+ borderWidth: 1,
341
+ borderColor: macOSColors.border.default,
342
+ backgroundColor: macOSColors.background.base
343
+ },
344
+ boolActive: {
345
+ borderColor: macOSColors.semantic.warning,
346
+ backgroundColor: macOSColors.semantic.warning + "18"
347
+ },
348
+ boolText: {
349
+ color: macOSColors.text.muted,
350
+ fontSize: 16,
351
+ fontWeight: "700",
352
+ fontFamily: "monospace"
353
+ },
354
+ boolTextActive: {
355
+ color: macOSColors.semantic.warning
356
+ }
357
+ });
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Everything editing a key involves, minus how it looks.
5
+ *
6
+ * The phone and the dashboard run the same editor: one buffered draft, one
7
+ * write on save, a selection the structural actions operate on, a modal for
8
+ * typing a value, and a guard so closing can't silently drop unsaved work.
9
+ * What differs is presentation — thumb-sized tiles under a full screen versus
10
+ * chips docked in a panel — which is a rendering concern and nothing more.
11
+ *
12
+ * Keeping the rules here means the two surfaces can't drift on the things that
13
+ * would actually hurt: whether a boolean opens an editor, whether a failed
14
+ * write closes the editor anyway, what "dirty" means.
15
+ */
16
+
17
+ import { useCallback, useEffect, useState } from "react";
18
+ import { getAtPath } from "@buoy-gg/shared-ui/dataViewer";
19
+ import { useTreeDraft } from "./useTreeDraft";
20
+ export function useKeyEditor({
21
+ value,
22
+ save,
23
+ onClose,
24
+ confirmDiscard
25
+ }) {
26
+ const draft = useTreeDraft(value, save);
27
+ const [selection, setSelection] = useState(null);
28
+ const [valuePath, setValuePath] = useState(null);
29
+ const {
30
+ begin
31
+ } = draft;
32
+ useEffect(() => {
33
+ begin();
34
+ // Seed the draft ONCE, when the editor opens. `begin` closes over the live
35
+ // value, whose identity changes every time the key list refreshes
36
+ // underneath us (a parsed JSON string is a new object each pass), so
37
+ // re-running would reset the draft mid-edit and discard the user's work.
38
+ // eslint-disable-next-line react-hooks/exhaustive-deps
39
+ }, []);
40
+
41
+ /**
42
+ * "Change this node". For a boolean that's a flip rather than a modal — the
43
+ * same rule `treeActionsFor` applies to the action controls, so the gesture
44
+ * and the button can't mean different things.
45
+ */
46
+ const openValueEditor = useCallback(path => {
47
+ const current = getAtPath(draft.value, path);
48
+ if (typeof current === "boolean") {
49
+ draft.apply({
50
+ kind: "replace",
51
+ path,
52
+ value: !current
53
+ });
54
+ return;
55
+ }
56
+ setValuePath(path);
57
+ }, [draft]);
58
+ const applyValue = useCallback(next => {
59
+ draft.apply({
60
+ kind: "replace",
61
+ path: valuePath ?? [],
62
+ value: next
63
+ });
64
+ setValuePath(null);
65
+ }, [draft, valuePath]);
66
+
67
+ // Only leave once the write actually landed — `commit` resolves false and
68
+ // keeps the draft on screen when the device refuses it, and closing anyway
69
+ // would throw the work away while showing an error nobody ever sees.
70
+ const saveAndClose = useCallback(() => {
71
+ void draft.commit().then(saved => saved && onClose());
72
+ }, [draft, onClose]);
73
+ const requestClose = useCallback(() => {
74
+ if (!draft.isDirty) {
75
+ onClose();
76
+ return;
77
+ }
78
+ // The draft is the only copy of this work, so closing over it silently is
79
+ // the one way this editor can lose something the user can't get back.
80
+ confirmDiscard({
81
+ save: saveAndClose,
82
+ discard: () => {
83
+ draft.discard();
84
+ onClose();
85
+ }
86
+ });
87
+ }, [confirmDiscard, draft, onClose, saveAndClose]);
88
+ return {
89
+ draft,
90
+ selection,
91
+ setSelection,
92
+ valuePath,
93
+ openValueEditor,
94
+ closeValueEditor: () => setValuePath(null),
95
+ applyValue,
96
+ openRawEditor: () => setValuePath([]),
97
+ requestClose,
98
+ saveAndClose
99
+ };
100
+ }
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Measure a container's width, for the layouts that switch between a card list
5
+ * and a wide table.
6
+ *
7
+ * Three things went wrong before this landed on a callback ref; all three are
8
+ * worth knowing, because the same trap is waiting in any other tool that wants
9
+ * a width-driven layout.
10
+ *
11
+ * 1. `onLayout` ALONE IS NOT ENOUGH. On react-native-web it never delivered its
12
+ * first callback for these subtrees. The node carries RNW's
13
+ * `__reactLayoutHandler`, and a ResizeObserver attached by hand fires on that
14
+ * very same node — so the handler is wired and the observer works; RNW's
15
+ * shared observer just never calls it. `width` stayed 0 and the table never
16
+ * appeared, silently. `onLayout` is still wired here because it works on
17
+ * native.
18
+ *
19
+ * 2. RE-MEASURING EVERY RENDER DEADLOCKS THE RENDERER. Filtering a list changes
20
+ * whether its scrollbar is present, which changes the container width, which
21
+ * re-renders, which re-measures — with no fixed point. An observer only fires
22
+ * when the size genuinely changes, so layout settles.
23
+ *
24
+ * 3. A MOUNT-ONLY EFFECT MISSES THE NODE. These components early-return a
25
+ * loading state before the measured container exists, so `ref.current` is
26
+ * null when a `useEffect(…, [])` runs, and it never runs again. A callback
27
+ * ref fires whenever the node actually attaches — including the second time.
28
+ */
29
+
30
+ import { useCallback, useRef, useState } from "react";
31
+
32
+ /** The bits of a DOM node we need. This package has no `dom` lib. */
33
+
34
+ function getResizeObserver() {
35
+ return globalThis.ResizeObserver;
36
+ }
37
+ function isMeasurable(node) {
38
+ return typeof node?.getBoundingClientRect === "function";
39
+ }
40
+ export function useMeasuredWidth() {
41
+ const [width, setWidth] = useState(0);
42
+ const observerRef = useRef(null);
43
+
44
+ // A sub-pixel wobble is not a layout change; anything larger is.
45
+ const apply = useCallback(measured => {
46
+ setWidth(prev => Math.abs(prev - measured) > 1 ? measured : prev);
47
+ }, []);
48
+ const ref = useCallback(node => {
49
+ observerRef.current?.disconnect();
50
+ observerRef.current = null;
51
+
52
+ // Detach (node === null) or a platform without DOM measurement: leave the
53
+ // last width in place so a remount doesn't flash the wrong layout.
54
+ if (!isMeasurable(node)) return;
55
+ apply(node.getBoundingClientRect().width);
56
+ const Observer = getResizeObserver();
57
+ if (!Observer) return;
58
+ const observer = new Observer(entries => {
59
+ const measured = entries[0]?.contentRect?.width;
60
+ if (typeof measured === "number") apply(measured);
61
+ });
62
+ observer.observe(node);
63
+ observerRef.current = observer;
64
+ }, [apply]);
65
+ const onLayout = useCallback(event => apply(event.nativeEvent.layout.width), [apply]);
66
+ return {
67
+ ref,
68
+ width,
69
+ onLayout
70
+ };
71
+ }