@usesidekick/react 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +246 -0
- package/dist/index.d.mts +358 -0
- package/dist/index.d.ts +358 -0
- package/dist/index.js +2470 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2403 -0
- package/dist/index.mjs.map +1 -0
- package/dist/jsx-dev-runtime.d.mts +21 -0
- package/dist/jsx-dev-runtime.d.ts +21 -0
- package/dist/jsx-dev-runtime.js +160 -0
- package/dist/jsx-dev-runtime.js.map +1 -0
- package/dist/jsx-dev-runtime.mjs +122 -0
- package/dist/jsx-dev-runtime.mjs.map +1 -0
- package/dist/jsx-runtime.d.mts +26 -0
- package/dist/jsx-runtime.d.ts +26 -0
- package/dist/jsx-runtime.js +150 -0
- package/dist/jsx-runtime.js.map +1 -0
- package/dist/jsx-runtime.mjs +109 -0
- package/dist/jsx-runtime.mjs.map +1 -0
- package/dist/server/index.d.mts +235 -0
- package/dist/server/index.d.ts +235 -0
- package/dist/server/index.js +642 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/index.mjs +597 -0
- package/dist/server/index.mjs.map +1 -0
- package/package.json +64 -0
- package/src/components/SidekickPanel.tsx +868 -0
- package/src/components/index.ts +1 -0
- package/src/context.tsx +157 -0
- package/src/flags.ts +47 -0
- package/src/index.ts +71 -0
- package/src/jsx-dev-runtime.ts +138 -0
- package/src/jsx-runtime.ts +159 -0
- package/src/loader.ts +35 -0
- package/src/primitives/behavior.ts +70 -0
- package/src/primitives/data.ts +91 -0
- package/src/primitives/index.ts +3 -0
- package/src/primitives/ui.ts +268 -0
- package/src/provider.tsx +1264 -0
- package/src/runtime-loader.ts +106 -0
- package/src/server/drizzle-adapter.ts +53 -0
- package/src/server/drizzle-schema.ts +16 -0
- package/src/server/generate.ts +578 -0
- package/src/server/handler.ts +343 -0
- package/src/server/index.ts +20 -0
- package/src/server/storage.ts +1 -0
- package/src/server/types.ts +49 -0
- package/src/types.ts +295 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DataPrimitives,
|
|
3
|
+
SidekickState,
|
|
4
|
+
ComputedField,
|
|
5
|
+
DataFilter,
|
|
6
|
+
DataTransform,
|
|
7
|
+
ApiInterceptor,
|
|
8
|
+
SortOption,
|
|
9
|
+
GroupByOption,
|
|
10
|
+
} from '../types';
|
|
11
|
+
|
|
12
|
+
function generateId(): string {
|
|
13
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
14
|
+
const r = (Math.random() * 16) | 0;
|
|
15
|
+
const v = c === 'x' ? r : (r & 0x3) | 0x8;
|
|
16
|
+
return v.toString(16);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function createDataPrimitives(
|
|
21
|
+
state: SidekickState,
|
|
22
|
+
currentOverrideId: string
|
|
23
|
+
): DataPrimitives {
|
|
24
|
+
return {
|
|
25
|
+
computed(fieldName, compute) {
|
|
26
|
+
const field: ComputedField = {
|
|
27
|
+
id: generateId(),
|
|
28
|
+
overrideId: currentOverrideId,
|
|
29
|
+
fieldName,
|
|
30
|
+
compute,
|
|
31
|
+
};
|
|
32
|
+
state.computedFields.set(fieldName, field);
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
addFilter(name, filter) {
|
|
36
|
+
const dataFilter: DataFilter = {
|
|
37
|
+
id: generateId(),
|
|
38
|
+
overrideId: currentOverrideId,
|
|
39
|
+
name,
|
|
40
|
+
filter,
|
|
41
|
+
};
|
|
42
|
+
state.filters.set(name, dataFilter);
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
transform(dataKey, transformFn) {
|
|
46
|
+
const transform: DataTransform = {
|
|
47
|
+
id: generateId(),
|
|
48
|
+
overrideId: currentOverrideId,
|
|
49
|
+
dataKey,
|
|
50
|
+
transform: transformFn,
|
|
51
|
+
};
|
|
52
|
+
state.transforms.set(dataKey, transform);
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
intercept(pathPattern, handler) {
|
|
56
|
+
const interceptor: ApiInterceptor = {
|
|
57
|
+
id: generateId(),
|
|
58
|
+
overrideId: currentOverrideId,
|
|
59
|
+
pathPattern,
|
|
60
|
+
handler,
|
|
61
|
+
};
|
|
62
|
+
state.interceptors.push(interceptor);
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
addSortOption(tableId, config) {
|
|
66
|
+
const sortOption: SortOption = {
|
|
67
|
+
id: generateId(),
|
|
68
|
+
overrideId: currentOverrideId,
|
|
69
|
+
tableId,
|
|
70
|
+
...config,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const existing = state.sortOptions.get(tableId) ?? [];
|
|
74
|
+
existing.push(sortOption);
|
|
75
|
+
state.sortOptions.set(tableId, existing);
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
addGroupBy(tableId, config) {
|
|
79
|
+
const groupByOption: GroupByOption = {
|
|
80
|
+
id: generateId(),
|
|
81
|
+
overrideId: currentOverrideId,
|
|
82
|
+
tableId,
|
|
83
|
+
...config,
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const existing = state.groupByOptions.get(tableId) ?? [];
|
|
87
|
+
existing.push(groupByOption);
|
|
88
|
+
state.groupByOptions.set(tableId, existing);
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { ComponentType } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
UIPrimitives,
|
|
4
|
+
SidekickState,
|
|
5
|
+
WrappedComponent,
|
|
6
|
+
AddedColumn,
|
|
7
|
+
ColumnRename,
|
|
8
|
+
HiddenColumn,
|
|
9
|
+
ColumnOrder,
|
|
10
|
+
RowFilter,
|
|
11
|
+
MenuItem,
|
|
12
|
+
TabItem,
|
|
13
|
+
PropsModifier,
|
|
14
|
+
ActionItem,
|
|
15
|
+
ValidationRule,
|
|
16
|
+
InjectedStyles,
|
|
17
|
+
DOMModification,
|
|
18
|
+
InjectionPoint,
|
|
19
|
+
} from '../types';
|
|
20
|
+
|
|
21
|
+
// Simple uuid generator for client-side use
|
|
22
|
+
function generateId(): string {
|
|
23
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
24
|
+
const r = (Math.random() * 16) | 0;
|
|
25
|
+
const v = c === 'x' ? r : (r & 0x3) | 0x8;
|
|
26
|
+
return v.toString(16);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function createUIPrimitives(
|
|
31
|
+
state: SidekickState,
|
|
32
|
+
currentOverrideId: string
|
|
33
|
+
): UIPrimitives {
|
|
34
|
+
return {
|
|
35
|
+
wrap(componentName, wrapper, options = {}) {
|
|
36
|
+
const wrapped: WrappedComponent = {
|
|
37
|
+
id: generateId(),
|
|
38
|
+
overrideId: currentOverrideId,
|
|
39
|
+
wrapper,
|
|
40
|
+
priority: options.priority ?? 0,
|
|
41
|
+
where: options.where,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const existing = state.wrappers.get(componentName) ?? [];
|
|
45
|
+
existing.push(wrapped);
|
|
46
|
+
existing.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
|
|
47
|
+
state.wrappers.set(componentName, existing);
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
replace(componentName, replacement) {
|
|
51
|
+
state.replacements.set(componentName, replacement);
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
addStyles(css) {
|
|
55
|
+
const styles: InjectedStyles = {
|
|
56
|
+
id: generateId(),
|
|
57
|
+
overrideId: currentOverrideId,
|
|
58
|
+
css,
|
|
59
|
+
};
|
|
60
|
+
state.styles.push(styles);
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
addColumn(tableId, config) {
|
|
64
|
+
const column: AddedColumn = {
|
|
65
|
+
id: generateId(),
|
|
66
|
+
overrideId: currentOverrideId,
|
|
67
|
+
tableId,
|
|
68
|
+
...config,
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const existing = state.columns.get(tableId) ?? [];
|
|
72
|
+
existing.push(column);
|
|
73
|
+
existing.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
|
|
74
|
+
state.columns.set(tableId, existing);
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
renameColumn(tableId, originalHeader, newHeader) {
|
|
78
|
+
const rename: ColumnRename = {
|
|
79
|
+
id: generateId(),
|
|
80
|
+
overrideId: currentOverrideId,
|
|
81
|
+
tableId,
|
|
82
|
+
originalHeader,
|
|
83
|
+
newHeader,
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const existing = state.columnRenames.get(tableId) ?? [];
|
|
87
|
+
existing.push(rename);
|
|
88
|
+
state.columnRenames.set(tableId, existing);
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
hideColumn(tableId, header) {
|
|
92
|
+
const hidden: HiddenColumn = {
|
|
93
|
+
id: generateId(),
|
|
94
|
+
overrideId: currentOverrideId,
|
|
95
|
+
tableId,
|
|
96
|
+
header,
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const existing = state.hiddenColumns.get(tableId) ?? [];
|
|
100
|
+
existing.push(hidden);
|
|
101
|
+
state.hiddenColumns.set(tableId, existing);
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
reorderColumns(tableId, order) {
|
|
105
|
+
const columnOrder: ColumnOrder = {
|
|
106
|
+
id: generateId(),
|
|
107
|
+
overrideId: currentOverrideId,
|
|
108
|
+
tableId,
|
|
109
|
+
order,
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// Only one order per table (last one wins)
|
|
113
|
+
state.columnOrders.set(tableId, columnOrder);
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
filterRows(tableId, filter) {
|
|
117
|
+
const rowFilter: RowFilter = {
|
|
118
|
+
id: generateId(),
|
|
119
|
+
overrideId: currentOverrideId,
|
|
120
|
+
tableId,
|
|
121
|
+
filter,
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const existing = state.rowFilters.get(tableId) ?? [];
|
|
125
|
+
existing.push(rowFilter);
|
|
126
|
+
state.rowFilters.set(tableId, existing);
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
addMenuItem(menuId, config) {
|
|
130
|
+
const item: MenuItem = {
|
|
131
|
+
id: generateId(),
|
|
132
|
+
overrideId: currentOverrideId,
|
|
133
|
+
menuId,
|
|
134
|
+
...config,
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const existing = state.menuItems.get(menuId) ?? [];
|
|
138
|
+
existing.push(item);
|
|
139
|
+
existing.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
|
|
140
|
+
state.menuItems.set(menuId, existing);
|
|
141
|
+
},
|
|
142
|
+
|
|
143
|
+
addTab(tabGroupId, config) {
|
|
144
|
+
const tab: TabItem = {
|
|
145
|
+
id: generateId(),
|
|
146
|
+
overrideId: currentOverrideId,
|
|
147
|
+
tabGroupId,
|
|
148
|
+
...config,
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const existing = state.tabs.get(tabGroupId) ?? [];
|
|
152
|
+
existing.push(tab);
|
|
153
|
+
existing.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
|
|
154
|
+
state.tabs.set(tabGroupId, existing);
|
|
155
|
+
},
|
|
156
|
+
|
|
157
|
+
modifyProps(componentId, modifier) {
|
|
158
|
+
const propsModifier: PropsModifier = {
|
|
159
|
+
id: generateId(),
|
|
160
|
+
overrideId: currentOverrideId,
|
|
161
|
+
componentId,
|
|
162
|
+
modifier,
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const existing = state.propsModifiers.get(componentId) ?? [];
|
|
166
|
+
existing.push(propsModifier);
|
|
167
|
+
state.propsModifiers.set(componentId, existing);
|
|
168
|
+
},
|
|
169
|
+
|
|
170
|
+
addAction(actionBarId, config) {
|
|
171
|
+
const action: ActionItem = {
|
|
172
|
+
id: generateId(),
|
|
173
|
+
overrideId: currentOverrideId,
|
|
174
|
+
actionBarId,
|
|
175
|
+
...config,
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const existing = state.actions.get(actionBarId) ?? [];
|
|
179
|
+
existing.push(action);
|
|
180
|
+
existing.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
|
|
181
|
+
state.actions.set(actionBarId, existing);
|
|
182
|
+
},
|
|
183
|
+
|
|
184
|
+
addValidation(formId, fieldName, validate) {
|
|
185
|
+
const rule: ValidationRule = {
|
|
186
|
+
id: generateId(),
|
|
187
|
+
overrideId: currentOverrideId,
|
|
188
|
+
formId,
|
|
189
|
+
fieldName,
|
|
190
|
+
validate,
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const existing = state.validations.get(formId) ?? [];
|
|
194
|
+
existing.push(rule);
|
|
195
|
+
state.validations.set(formId, existing);
|
|
196
|
+
},
|
|
197
|
+
|
|
198
|
+
setText(selector, text) {
|
|
199
|
+
if (typeof text !== 'string') {
|
|
200
|
+
console.warn(`[Sidekick] setText expects a string value, got ${typeof text}. Ignoring.`);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
const mod: DOMModification = {
|
|
204
|
+
id: generateId(),
|
|
205
|
+
overrideId: currentOverrideId,
|
|
206
|
+
selector,
|
|
207
|
+
type: 'setText',
|
|
208
|
+
value: text,
|
|
209
|
+
};
|
|
210
|
+
state.domModifications.push(mod);
|
|
211
|
+
},
|
|
212
|
+
|
|
213
|
+
setAttribute(selector, attr, value) {
|
|
214
|
+
const mod: DOMModification = {
|
|
215
|
+
id: generateId(),
|
|
216
|
+
overrideId: currentOverrideId,
|
|
217
|
+
selector,
|
|
218
|
+
type: 'setAttribute',
|
|
219
|
+
value: { attr, value },
|
|
220
|
+
};
|
|
221
|
+
state.domModifications.push(mod);
|
|
222
|
+
},
|
|
223
|
+
|
|
224
|
+
setStyle(selector, styles) {
|
|
225
|
+
const mod: DOMModification = {
|
|
226
|
+
id: generateId(),
|
|
227
|
+
overrideId: currentOverrideId,
|
|
228
|
+
selector,
|
|
229
|
+
type: 'setStyle',
|
|
230
|
+
value: styles,
|
|
231
|
+
};
|
|
232
|
+
state.domModifications.push(mod);
|
|
233
|
+
},
|
|
234
|
+
|
|
235
|
+
addClass(selector, className) {
|
|
236
|
+
const mod: DOMModification = {
|
|
237
|
+
id: generateId(),
|
|
238
|
+
overrideId: currentOverrideId,
|
|
239
|
+
selector,
|
|
240
|
+
type: 'addClass',
|
|
241
|
+
value: className,
|
|
242
|
+
};
|
|
243
|
+
state.domModifications.push(mod);
|
|
244
|
+
},
|
|
245
|
+
|
|
246
|
+
removeClass(selector, className) {
|
|
247
|
+
const mod: DOMModification = {
|
|
248
|
+
id: generateId(),
|
|
249
|
+
overrideId: currentOverrideId,
|
|
250
|
+
selector,
|
|
251
|
+
type: 'removeClass',
|
|
252
|
+
value: className,
|
|
253
|
+
};
|
|
254
|
+
state.domModifications.push(mod);
|
|
255
|
+
},
|
|
256
|
+
|
|
257
|
+
inject(selector, component, position = 'after') {
|
|
258
|
+
const injection: InjectionPoint = {
|
|
259
|
+
id: generateId(),
|
|
260
|
+
overrideId: currentOverrideId,
|
|
261
|
+
selector,
|
|
262
|
+
position,
|
|
263
|
+
component,
|
|
264
|
+
};
|
|
265
|
+
state.injections.push(injection);
|
|
266
|
+
},
|
|
267
|
+
};
|
|
268
|
+
}
|