@arcanewizards/timecode-toolbox 0.0.3

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 (41) hide show
  1. package/.turbo/turbo-build.log +55 -0
  2. package/CHANGELOG.md +24 -0
  3. package/eslint.config.mjs +49 -0
  4. package/package.json +74 -0
  5. package/src/app.tsx +147 -0
  6. package/src/components/backend/index.ts +6 -0
  7. package/src/components/backend/toolbox-root.ts +119 -0
  8. package/src/components/frontend/constants.ts +81 -0
  9. package/src/components/frontend/entrypoint.ts +12 -0
  10. package/src/components/frontend/frontend.css +108 -0
  11. package/src/components/frontend/index.tsx +46 -0
  12. package/src/components/frontend/toolbox/content.tsx +45 -0
  13. package/src/components/frontend/toolbox/context.tsx +63 -0
  14. package/src/components/frontend/toolbox/core/size-aware-div.tsx +51 -0
  15. package/src/components/frontend/toolbox/core/timecode-display.tsx +592 -0
  16. package/src/components/frontend/toolbox/generators.tsx +318 -0
  17. package/src/components/frontend/toolbox/inputs.tsx +484 -0
  18. package/src/components/frontend/toolbox/outputs.tsx +581 -0
  19. package/src/components/frontend/toolbox/preferences.ts +25 -0
  20. package/src/components/frontend/toolbox/root.tsx +335 -0
  21. package/src/components/frontend/toolbox/settings.tsx +54 -0
  22. package/src/components/frontend/toolbox/types.ts +28 -0
  23. package/src/components/frontend/toolbox/util.tsx +61 -0
  24. package/src/components/proto.ts +420 -0
  25. package/src/config.ts +7 -0
  26. package/src/generators/clock.tsx +206 -0
  27. package/src/generators/index.tsx +15 -0
  28. package/src/index.ts +38 -0
  29. package/src/inputs/artnet.tsx +305 -0
  30. package/src/inputs/index.tsx +13 -0
  31. package/src/inputs/tcnet.tsx +272 -0
  32. package/src/outputs/artnet.tsx +170 -0
  33. package/src/outputs/index.tsx +11 -0
  34. package/src/start.ts +47 -0
  35. package/src/tree.ts +133 -0
  36. package/src/types.ts +12 -0
  37. package/src/urls.ts +49 -0
  38. package/src/util.ts +82 -0
  39. package/tailwind.config.cjs +7 -0
  40. package/tsconfig.json +10 -0
  41. package/tsup.config.ts +10 -0
@@ -0,0 +1,318 @@
1
+ import { FC, useCallback, useContext, useState } from 'react';
2
+ import { STRINGS } from '../constants';
3
+ import { PrimaryToolboxSection } from './util';
4
+ import { NoToolboxChildren } from './content';
5
+ import { ConfigContext, useApplicationState } from './context';
6
+ import { AssignToOutputCallback, DialogMode, SettingsProps } from './types';
7
+ import {
8
+ ControlButton,
9
+ ControlColorSelect,
10
+ ControlDialog,
11
+ ControlDialogButtons,
12
+ ControlInput,
13
+ ControlLabel,
14
+ } from '@arcanewizards/sigil/frontend/controls';
15
+ import { GeneratorConfig, GeneratorDefinition } from '../../proto';
16
+ import { v4 as uuidv4 } from 'uuid';
17
+ import {
18
+ ChangeCommitContext,
19
+ useChangeCommitBoundary,
20
+ } from '@arcanewizards/sigil/frontend/context';
21
+ import { TimecodeTreeDisplay } from './core/timecode-display';
22
+
23
+ const ClockSpecificSettings: FC<SettingsProps<GeneratorDefinition>> = ({
24
+ data,
25
+ updateSettings,
26
+ }) => {
27
+ const { commitChanges } = useContext(ChangeCommitContext);
28
+
29
+ if (data.type !== 'clock') {
30
+ return null;
31
+ }
32
+
33
+ return (
34
+ <>
35
+ <ControlLabel>Speed</ControlLabel>
36
+ <ControlInput
37
+ position="both"
38
+ type="string"
39
+ value={data.speed?.toString() ?? ''}
40
+ placeholder={`Default (1)`}
41
+ onChange={(value, enterPressed) => {
42
+ const speed = value ? parseFloat(value) : 1;
43
+ if (speed !== undefined && isNaN(speed)) {
44
+ return;
45
+ }
46
+ updateSettings((current) => ({
47
+ ...current,
48
+ speed,
49
+ }));
50
+ if (enterPressed) {
51
+ commitChanges();
52
+ }
53
+ }}
54
+ />
55
+ </>
56
+ );
57
+ };
58
+
59
+ type GeneratorSettingsDialogProps = {
60
+ target: DialogMode['target'];
61
+ generator: GeneratorDefinition['type'];
62
+ close: () => void;
63
+ };
64
+
65
+ export const GeneratorSettingsDialog: FC<GeneratorSettingsDialogProps> = ({
66
+ target,
67
+ generator,
68
+ close,
69
+ }) => {
70
+ const { config, updateConfig } = useContext(ConfigContext);
71
+ const [newData, setNewData] = useState<GeneratorConfig>({
72
+ name: '',
73
+ definition: {
74
+ type: generator,
75
+ speed: 1,
76
+ },
77
+ });
78
+
79
+ const updateSettings: SettingsProps<GeneratorConfig>['updateSettings'] =
80
+ useCallback(
81
+ (change) => {
82
+ if (target.type === 'add') {
83
+ setNewData(change);
84
+ } else {
85
+ updateConfig((current) => {
86
+ const existing = current.generators?.[target.uuid];
87
+ if (!existing) {
88
+ return current;
89
+ }
90
+ return {
91
+ ...current,
92
+ generators: {
93
+ ...current.generators,
94
+ [target.uuid]: change(existing),
95
+ },
96
+ };
97
+ });
98
+ }
99
+ },
100
+ [target, updateConfig],
101
+ );
102
+
103
+ const updateDefinition = useCallback(
104
+ (change: (current: GeneratorDefinition) => GeneratorDefinition) => {
105
+ updateSettings((current) => ({
106
+ ...current,
107
+ definition: change(current.definition),
108
+ }));
109
+ },
110
+ [updateSettings],
111
+ );
112
+
113
+ const addGenerator = useCallback(() => {
114
+ updateConfig((current) => {
115
+ return {
116
+ ...current,
117
+ generators: {
118
+ ...current.generators,
119
+ [uuidv4()]: newData,
120
+ },
121
+ };
122
+ });
123
+ close();
124
+ }, [newData, close, updateConfig]);
125
+
126
+ const resolvedTarget =
127
+ target.type === 'add' ? 'add' : config.generators?.[target.uuid];
128
+
129
+ const data = resolvedTarget === 'add' ? newData : resolvedTarget;
130
+
131
+ const commitChanges = useCallback(() => {
132
+ if (target.type === 'add') {
133
+ addGenerator();
134
+ } else {
135
+ close();
136
+ }
137
+ }, [target, addGenerator, close]);
138
+
139
+ const commitBoundary = useChangeCommitBoundary(data, commitChanges);
140
+
141
+ if (!data) {
142
+ return null;
143
+ }
144
+
145
+ return (
146
+ <ChangeCommitContext.Provider value={commitBoundary}>
147
+ <ControlDialog
148
+ dialogClosed={close}
149
+ title={
150
+ target.type === 'add'
151
+ ? STRINGS.generators.addDialog(STRINGS.generators.type[generator])
152
+ : STRINGS.generators.editDialog(
153
+ STRINGS.generators.type[generator],
154
+ data.name || '',
155
+ )
156
+ }
157
+ >
158
+ <ControlLabel>Name</ControlLabel>
159
+ <ControlInput
160
+ position="both"
161
+ type="string"
162
+ value={data.name ?? ''}
163
+ placeholder={`No name specified`}
164
+ onChange={(name, enterPressed) => {
165
+ if (enterPressed) {
166
+ commitBoundary.commitChanges();
167
+ }
168
+ updateSettings((current) => ({
169
+ ...current,
170
+ name,
171
+ }));
172
+ }}
173
+ />
174
+ <ControlLabel>Color</ControlLabel>
175
+ <ControlColorSelect
176
+ position="both"
177
+ color={data.color ?? ''}
178
+ variant="standard"
179
+ placeholder="Default"
180
+ onChange={(color) => {
181
+ updateSettings((current) => ({
182
+ ...current,
183
+ color,
184
+ }));
185
+ }}
186
+ />
187
+ {data.definition.type === 'clock' ? (
188
+ <ClockSpecificSettings
189
+ data={data.definition}
190
+ updateSettings={updateDefinition}
191
+ />
192
+ ) : null}
193
+ {resolvedTarget === 'add' ? (
194
+ <ControlDialogButtons>
195
+ <ControlButton onClick={close} variant="large">
196
+ Cancel
197
+ </ControlButton>
198
+ <ControlButton onClick={addGenerator} variant="large">
199
+ Add Generator
200
+ </ControlButton>
201
+ </ControlDialogButtons>
202
+ ) : (
203
+ <ControlDialogButtons>
204
+ <ControlButton onClick={close} variant="large">
205
+ Close
206
+ </ControlButton>
207
+ </ControlDialogButtons>
208
+ )}
209
+ </ControlDialog>
210
+ </ChangeCommitContext.Provider>
211
+ );
212
+ };
213
+
214
+ type GeneratorDisplayProps = {
215
+ uuid: string;
216
+ config: GeneratorConfig;
217
+ setDialogMode: (mode: DialogMode | null) => void;
218
+ assignToOutput: AssignToOutputCallback;
219
+ };
220
+
221
+ const GeneratorDisplay: FC<GeneratorDisplayProps> = ({
222
+ uuid,
223
+ config,
224
+ setDialogMode,
225
+ assignToOutput,
226
+ }) => {
227
+ const { generators } = useApplicationState();
228
+ const state = generators[uuid];
229
+
230
+ return (
231
+ <TimecodeTreeDisplay
232
+ id={['generator', uuid]}
233
+ config={{ delayMs: config.delayMs ?? null }}
234
+ type={STRINGS.generators.type[config.definition.type]}
235
+ name={config.name ? [config.name] : []}
236
+ color={config.color}
237
+ timecode={state?.timecode ?? null}
238
+ namePlaceholder={`Unnamed Generator`}
239
+ buttons={
240
+ <>
241
+ <ControlButton
242
+ variant="large"
243
+ title="Edit Generator"
244
+ onClick={() =>
245
+ setDialogMode({
246
+ section: {
247
+ type: 'generators',
248
+ generator: config.definition.type,
249
+ },
250
+ target: { type: 'edit', uuid },
251
+ })
252
+ }
253
+ icon="edit"
254
+ />
255
+ </>
256
+ }
257
+ assignToOutput={assignToOutput}
258
+ />
259
+ );
260
+ };
261
+
262
+ export type GeneratorsSectionProps = {
263
+ setDialogMode: (mode: DialogMode | null) => void;
264
+ assignToOutput: AssignToOutputCallback;
265
+ };
266
+
267
+ export const GeneratorsSection: FC<GeneratorsSectionProps> = ({
268
+ setDialogMode,
269
+ assignToOutput,
270
+ }) => {
271
+ const { config } = useContext(ConfigContext);
272
+ return (
273
+ <PrimaryToolboxSection
274
+ title={STRINGS.generators.title}
275
+ buttons={
276
+ <>
277
+ {(['clock'] as const).map((generator) => (
278
+ <ControlButton
279
+ key={generator}
280
+ onClick={() =>
281
+ setDialogMode({
282
+ section: { type: 'generators', generator },
283
+ target: { type: 'add' },
284
+ })
285
+ }
286
+ variant="toolbar"
287
+ icon="add"
288
+ >
289
+ {STRINGS.outputs.addButton(STRINGS.generators.type[generator])}
290
+ </ControlButton>
291
+ ))}
292
+ </>
293
+ }
294
+ >
295
+ {Object.entries(config.generators ?? {}).length === 0 ? (
296
+ <NoToolboxChildren text={STRINGS.generators.noChildren} />
297
+ ) : (
298
+ <div
299
+ className="
300
+ grid grow grid-cols-1 gap-px
301
+ min-[600px]:grid-cols-2
302
+ min-[900px]:grid-cols-3
303
+ "
304
+ >
305
+ {Object.entries(config.generators).map(([uuid, generator]) => (
306
+ <GeneratorDisplay
307
+ key={uuid}
308
+ uuid={uuid}
309
+ config={generator}
310
+ setDialogMode={setDialogMode}
311
+ assignToOutput={assignToOutput}
312
+ />
313
+ ))}
314
+ </div>
315
+ )}
316
+ </PrimaryToolboxSection>
317
+ );
318
+ };