@developer_tribe/react-builder 1.0.1 → 1.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 (218) hide show
  1. package/dist/AttributesEditor.d.ts +3 -1
  2. package/dist/DeviceMockFrame.d.ts +2 -1
  3. package/dist/RenderPage.d.ts +5 -3
  4. package/dist/attributes-editor/Field.d.ts +17 -0
  5. package/dist/attributes-editor/FieldInfoTooltip.d.ts +7 -0
  6. package/dist/attributes-editor/LayoutPreviewPicker.d.ts +12 -0
  7. package/dist/attributes-editor/SpecialCategorySection.d.ts +20 -0
  8. package/dist/attributes-editor/types.d.ts +14 -0
  9. package/dist/background.jpg +0 -0
  10. package/dist/build-components/BackgroundImage/BackgroundImage.d.ts +5 -0
  11. package/dist/build-components/BackgroundImage/BackgroundImageProps.generated.d.ts +44 -0
  12. package/dist/build-components/Button/Button.d.ts +1 -1
  13. package/dist/build-components/Button/ButtonProps.generated.d.ts +33 -1
  14. package/dist/build-components/Carousel/CarouselProps.generated.d.ts +34 -1
  15. package/dist/build-components/CarouselButtons/CarouselButtonsProps.generated.d.ts +32 -0
  16. package/dist/build-components/CarouselDots/CarouselDotsProps.generated.d.ts +32 -0
  17. package/dist/build-components/CarouselItem/CarouselItemProps.generated.d.ts +34 -1
  18. package/dist/build-components/CarouselProvider/CarouselProviderProps.generated.d.ts +34 -1
  19. package/dist/build-components/Image/ImageProps.generated.d.ts +32 -3
  20. package/dist/build-components/Onboard/OnboardProps.generated.d.ts +34 -1
  21. package/dist/build-components/OnboardButton/OnboardButtonProps.generated.d.ts +32 -0
  22. package/dist/build-components/OnboardButtons/OnboardButtonsProps.generated.d.ts +32 -0
  23. package/dist/build-components/OnboardDot/OnboardDot.d.ts +1 -1
  24. package/dist/build-components/OnboardDot/OnboardDotProps.generated.d.ts +29 -0
  25. package/dist/build-components/OnboardFooter/OnboardFooterProps.generated.d.ts +11 -5
  26. package/dist/build-components/OnboardImage/OnboardImageProps.generated.d.ts +32 -3
  27. package/dist/build-components/OnboardItem/OnboardItemProps.generated.d.ts +31 -3
  28. package/dist/build-components/OnboardProvider/OnboardProviderProps.generated.d.ts +32 -5
  29. package/dist/build-components/OnboardSubtitle/OnboardSubtitleProps.generated.d.ts +11 -5
  30. package/dist/build-components/OnboardTitle/OnboardTitleProps.generated.d.ts +11 -5
  31. package/dist/build-components/Text/TextProps.generated.d.ts +11 -5
  32. package/dist/build-components/View/ViewProps.generated.d.ts +10 -4
  33. package/dist/build-components/index.d.ts +2 -1
  34. package/dist/build-components/patterns.generated.d.ts +6288 -136
  35. package/dist/components/AttributesEditorPanel.d.ts +3 -4
  36. package/dist/components/Breadcrumb.d.ts +3 -1
  37. package/dist/components/Builder.d.ts +2 -1
  38. package/dist/components/BuilderButton.d.ts +9 -0
  39. package/dist/components/Checkbox.d.ts +17 -0
  40. package/dist/components/DeviceButton.d.ts +8 -0
  41. package/dist/components/DeviceNavigationBar.d.ts +10 -0
  42. package/dist/components/DeviceStatusBar.d.ts +9 -0
  43. package/dist/components/EditorHeader.d.ts +3 -8
  44. package/dist/index.cjs.js +5 -5
  45. package/dist/index.cjs.js.map +1 -1
  46. package/dist/index.d.ts +2 -2
  47. package/dist/index.esm.js +5 -5
  48. package/dist/index.esm.js.map +1 -1
  49. package/dist/mockOS/components/MockLaunchScreenComponent.d.ts +6 -0
  50. package/dist/mockOS/components/MockOSRouter.d.ts +8 -0
  51. package/dist/mockOS/components/PermissionModal.d.ts +9 -0
  52. package/dist/mockOS/context/MockOSContext.d.ts +36 -0
  53. package/dist/mockOS/hooks/useMockNavigation.d.ts +3 -0
  54. package/dist/mockOS/hooks/useMockPermission.d.ts +3 -0
  55. package/dist/mockOS/index.d.ts +9 -0
  56. package/dist/mockOS/managers/mockPermissionManager.d.ts +10 -0
  57. package/dist/mockOS/managers/navigationManager.d.ts +17 -0
  58. package/dist/modals/AddComponentModal.d.ts +8 -0
  59. package/dist/modals/ColorModal.d.ts +11 -0
  60. package/dist/modals/DeviceSelectorModal.d.ts +9 -0
  61. package/dist/modals/LocalicationModal.d.ts +8 -0
  62. package/dist/modals/Modal.d.ts +12 -0
  63. package/dist/modals/index.d.ts +5 -0
  64. package/dist/pages/ProjectPage.d.ts +3 -3
  65. package/dist/pages/tabs/BuilderPanel.d.ts +8 -0
  66. package/dist/pages/tabs/{DebugTab.d.ts → SideTool.d.ts} +2 -2
  67. package/dist/store.d.ts +7 -3
  68. package/dist/styles.css +1 -1
  69. package/dist/types/Project.d.ts +11 -0
  70. package/dist/utils/analyseNode.d.ts +1 -0
  71. package/dist/utils/extractTextStyle.d.ts +8 -1
  72. package/dist/utils/extractViewStyle.d.ts +8 -1
  73. package/dist/utils/parseColor.d.ts +7 -0
  74. package/dist/utils/patterns.d.ts +24 -0
  75. package/package.json +2 -1
  76. package/scripts/prebuild/utils/createGeneratedProps.js +11 -3
  77. package/scripts/prebuild/utils/validateAllComponentsOrThrow.js +45 -6
  78. package/scripts/prebuild/utils/validatePatternJson.js +13 -5
  79. package/src/AttributesEditor.tsx +493 -310
  80. package/src/DeviceMockFrame.tsx +21 -37
  81. package/src/RenderPage.tsx +86 -7
  82. package/src/assets/images/android.svg +42 -42
  83. package/src/assets/images/apple.svg +15 -15
  84. package/src/attributes-editor/Field.tsx +669 -0
  85. package/src/attributes-editor/FieldInfoTooltip.tsx +49 -0
  86. package/src/attributes-editor/LayoutPreviewPicker.tsx +199 -0
  87. package/src/attributes-editor/SpecialCategorySection.tsx +285 -0
  88. package/src/attributes-editor/types.ts +30 -0
  89. package/src/build-components/BackgroundImage/BackgroundImage.tsx +87 -0
  90. package/src/build-components/BackgroundImage/BackgroundImageProps.generated.ts +60 -0
  91. package/src/build-components/BackgroundImage/pattern.json +45 -0
  92. package/src/build-components/Button/Button.tsx +37 -2
  93. package/src/build-components/Button/ButtonProps.generated.ts +44 -1
  94. package/src/build-components/Button/pattern.json +31 -2
  95. package/src/build-components/Carousel/Carousel.tsx +39 -2
  96. package/src/build-components/Carousel/CarouselProps.generated.ts +46 -1
  97. package/src/build-components/Carousel/pattern.json +10 -0
  98. package/src/build-components/CarouselButtons/CarouselButtons.tsx +21 -2
  99. package/src/build-components/CarouselButtons/CarouselButtonsProps.generated.ts +43 -0
  100. package/src/build-components/CarouselButtons/pattern.json +22 -0
  101. package/src/build-components/CarouselDots/CarouselDots.tsx +49 -8
  102. package/src/build-components/CarouselDots/CarouselDotsProps.generated.ts +43 -0
  103. package/src/build-components/CarouselDots/pattern.json +15 -0
  104. package/src/build-components/CarouselItem/CarouselItem.tsx +21 -2
  105. package/src/build-components/CarouselItem/CarouselItemProps.generated.ts +46 -1
  106. package/src/build-components/CarouselItem/pattern.json +7 -0
  107. package/src/build-components/CarouselProvider/CarouselProvider.tsx +21 -2
  108. package/src/build-components/CarouselProvider/CarouselProviderProps.generated.ts +46 -1
  109. package/src/build-components/CarouselProvider/pattern.json +7 -0
  110. package/src/build-components/Image/Image.tsx +33 -2
  111. package/src/build-components/Image/ImageProps.generated.ts +43 -3
  112. package/src/build-components/Image/pattern.json +46 -3
  113. package/src/build-components/Onboard/Onboard.tsx +6 -1
  114. package/src/build-components/Onboard/OnboardProps.generated.ts +46 -1
  115. package/src/build-components/Onboard/pattern.json +11 -0
  116. package/src/build-components/OnboardButton/OnboardButton.tsx +54 -6
  117. package/src/build-components/OnboardButton/OnboardButtonProps.generated.ts +43 -0
  118. package/src/build-components/OnboardButton/pattern.json +71 -5
  119. package/src/build-components/OnboardButtons/OnboardButtons.tsx +33 -11
  120. package/src/build-components/OnboardButtons/OnboardButtonsProps.generated.ts +43 -0
  121. package/src/build-components/OnboardButtons/pattern.json +70 -4
  122. package/src/build-components/OnboardDot/OnboardDot.tsx +113 -4
  123. package/src/build-components/OnboardDot/OnboardDotProps.generated.ts +29 -0
  124. package/src/build-components/OnboardDot/pattern.json +55 -2
  125. package/src/build-components/OnboardFooter/OnboardFooter.tsx +20 -4
  126. package/src/build-components/OnboardFooter/OnboardFooterProps.generated.ts +11 -5
  127. package/src/build-components/OnboardFooter/pattern.json +58 -2
  128. package/src/build-components/OnboardImage/OnboardImage.tsx +49 -5
  129. package/src/build-components/OnboardImage/OnboardImageProps.generated.ts +43 -3
  130. package/src/build-components/OnboardImage/pattern.json +21 -0
  131. package/src/build-components/OnboardItem/OnboardItem.tsx +17 -1
  132. package/src/build-components/OnboardItem/OnboardItemProps.generated.ts +42 -3
  133. package/src/build-components/OnboardItem/pattern.json +38 -2
  134. package/src/build-components/OnboardProvider/OnboardProvider.tsx +52 -18
  135. package/src/build-components/OnboardProvider/OnboardProviderProps.generated.ts +44 -5
  136. package/src/build-components/OnboardProvider/pattern.json +44 -5
  137. package/src/build-components/OnboardSubtitle/OnboardSubtitleProps.generated.ts +11 -5
  138. package/src/build-components/OnboardSubtitle/pattern.json +7 -1
  139. package/src/build-components/OnboardTitle/OnboardTitleProps.generated.ts +11 -5
  140. package/src/build-components/OnboardTitle/pattern.json +7 -1
  141. package/src/build-components/RenderNode.generated.tsx +3 -0
  142. package/src/build-components/Text/Text.tsx +34 -6
  143. package/src/build-components/Text/TextProps.generated.ts +11 -5
  144. package/src/build-components/Text/pattern.json +38 -2
  145. package/src/build-components/View/View.tsx +33 -6
  146. package/src/build-components/View/ViewProps.generated.ts +10 -4
  147. package/src/build-components/View/pattern.json +285 -19
  148. package/src/build-components/index.ts +5 -0
  149. package/src/build-components/patterns.generated.ts +6346 -143
  150. package/src/components/AttributesEditorPanel.tsx +17 -64
  151. package/src/components/Breadcrumb.tsx +37 -5
  152. package/src/components/Builder.tsx +311 -108
  153. package/src/components/BuilderButton.tsx +127 -0
  154. package/src/components/Checkbox.tsx +81 -0
  155. package/src/components/DeviceButton.tsx +39 -0
  156. package/src/components/DeviceNavigationBar.tsx +201 -0
  157. package/src/components/DeviceStatusBar.tsx +85 -0
  158. package/src/components/EditorHeader.tsx +26 -74
  159. package/src/index.ts +2 -2
  160. package/src/mockOS/components/MockLaunchScreenComponent.tsx +43 -0
  161. package/src/mockOS/components/MockOSRouter.tsx +123 -0
  162. package/src/mockOS/components/PermissionModal.tsx +270 -0
  163. package/src/mockOS/context/MockOSContext.tsx +179 -0
  164. package/src/mockOS/hooks/useMockNavigation.ts +11 -0
  165. package/src/mockOS/hooks/useMockPermission.ts +11 -0
  166. package/src/mockOS/index.ts +26 -0
  167. package/src/mockOS/managers/mockPermissionManager.ts +54 -0
  168. package/src/mockOS/managers/navigationManager.ts +91 -0
  169. package/src/modals/AddComponentModal.tsx +313 -0
  170. package/src/modals/ColorModal.tsx +425 -0
  171. package/src/modals/DeviceSelectorModal.tsx +57 -0
  172. package/src/modals/LocalicationModal.tsx +54 -0
  173. package/src/modals/Modal.tsx +57 -0
  174. package/src/modals/index.ts +5 -0
  175. package/src/pages/ProjectPage.tsx +307 -71
  176. package/src/pages/tabs/{BuilderTab.tsx → BuilderPanel.tsx} +13 -9
  177. package/src/pages/tabs/SideTool.tsx +259 -0
  178. package/src/size-matters/index.ts +27 -5
  179. package/src/store.ts +13 -5
  180. package/src/styles/base/_global.scss +404 -0
  181. package/src/styles/components/_attributes-editor.scss +273 -0
  182. package/src/styles/components/_editor-shell.scss +212 -0
  183. package/src/styles/components/_mockos-router.scss +140 -0
  184. package/src/styles/components/_ui-components.scss +183 -0
  185. package/src/styles/foundation/_colors.scss +8 -0
  186. package/src/styles/{_mixins.scss → foundation/_mixins.scss} +5 -4
  187. package/src/styles/{_reset.scss → foundation/_reset.scss} +5 -2
  188. package/src/styles/foundation/_sizes.scss +37 -0
  189. package/src/styles/foundation/_typography.scss +4 -0
  190. package/src/styles/foundation/_variables.scss +3 -0
  191. package/src/styles/index.scss +22 -136
  192. package/src/styles/layout/_builder.scss +124 -0
  193. package/src/styles/layout/_pages.scss +3 -0
  194. package/src/styles/modals/_add-component.scss +122 -0
  195. package/src/styles/modals/_color-modal.scss +159 -0
  196. package/src/styles/modals/_device-selector.scss +18 -0
  197. package/src/styles/modals/_localication-modal.scss +68 -0
  198. package/src/styles/modals/_modal-shell.scss +46 -0
  199. package/src/styles/utilities/_carousel.scss +125 -0
  200. package/src/types/Project.ts +14 -0
  201. package/src/types/images.d.ts +8 -0
  202. package/src/utils/analyseNode.ts +98 -0
  203. package/src/utils/extractTextStyle.ts +28 -10
  204. package/src/utils/extractViewStyle.ts +77 -9
  205. package/src/utils/parseColor.ts +43 -0
  206. package/src/utils/patterns.ts +33 -0
  207. package/dist/build-components/OnboardDot/OnboardExpandingDotProps.generated.d.ts +0 -10
  208. package/dist/pages/tabs/BuilderTab.d.ts +0 -9
  209. package/dist/pages/tabs/PreviewTab.d.ts +0 -3
  210. package/src/build-components/OnboardDot/OnboardExpandingDotProps.generated.ts +0 -20
  211. package/src/pages/tabs/DebugTab.tsx +0 -23
  212. package/src/pages/tabs/PreviewTab.tsx +0 -194
  213. package/src/styles/_variables.scss +0 -27
  214. package/src/styles/builder.scss +0 -60
  215. package/src/styles/components.scss +0 -88
  216. package/src/styles/editor.scss +0 -174
  217. package/src/styles/global.scss +0 -200
  218. package/src/styles/pages.scss +0 -2
@@ -0,0 +1,669 @@
1
+ import React, { useCallback, useEffect, useMemo, useState } from 'react';
2
+ import type { ViewPropsGenerated } from '../build-components/View/ViewProps.generated';
3
+ import { ColorModal, resolveProjectColorValue } from '../modals/ColorModal';
4
+ import type { ProjectColors } from '../types/Project';
5
+ import {
6
+ getArrayItemType,
7
+ getTypeSchema,
8
+ isPrimitiveType,
9
+ } from '../utils/patterns';
10
+ import { Checkbox } from '../components/Checkbox';
11
+ import { LayoutPreviewPicker } from './LayoutPreviewPicker';
12
+ import { LayoutContext, LayoutFieldName, isBooleanFieldType } from './types';
13
+
14
+ export type FieldProps = {
15
+ name: string;
16
+ type: string | string[];
17
+ value: any;
18
+ onChange: (v: any) => void;
19
+ componentType?: string;
20
+ projectColors?: ProjectColors;
21
+ layoutContext?: LayoutContext;
22
+ viewAttributes?: Partial<ViewPropsGenerated['attributes']>;
23
+ label?: React.ReactNode;
24
+ preferredScale?: string;
25
+ };
26
+
27
+ const layoutFieldNames: LayoutFieldName[] = [
28
+ 'flexDirection',
29
+ 'alignItems',
30
+ 'justifyContent',
31
+ ];
32
+
33
+ function isLayoutField(name: string): name is LayoutFieldName {
34
+ return layoutFieldNames.includes(name as LayoutFieldName);
35
+ }
36
+
37
+ export function Field({
38
+ name,
39
+ type,
40
+ value,
41
+ onChange,
42
+ componentType,
43
+ projectColors,
44
+ layoutContext,
45
+ viewAttributes,
46
+ label,
47
+ preferredScale,
48
+ }: FieldProps) {
49
+ if (Array.isArray(type)) {
50
+ if (isLayoutField(name)) {
51
+ const enumOptions = type.filter(
52
+ (opt): opt is string => typeof opt === 'string' && opt.length > 0,
53
+ );
54
+ return (
55
+ <LayoutPreviewPicker
56
+ mode={name}
57
+ options={enumOptions}
58
+ value={typeof value === 'string' ? value : undefined}
59
+ onChange={onChange}
60
+ layoutContext={layoutContext}
61
+ viewAttributes={viewAttributes}
62
+ />
63
+ );
64
+ }
65
+ return (
66
+ <select
67
+ value={value ?? ''}
68
+ onChange={(e) => onChange(e.target.value)}
69
+ className="input"
70
+ >
71
+ <option value="">(none)</option>
72
+ {type.map((opt) => (
73
+ <option key={opt} value={opt}>
74
+ {opt}
75
+ </option>
76
+ ))}
77
+ </select>
78
+ );
79
+ }
80
+
81
+ const itemType = typeof type === 'string' ? getArrayItemType(type) : null;
82
+ if (itemType) {
83
+ const arr: any[] = Array.isArray(value) ? value : [];
84
+
85
+ if (isPrimitiveType(itemType)) {
86
+ const renderPrimitiveArrayItem = (itemValue: any, idx: number) => {
87
+ switch (itemType) {
88
+ case 'number':
89
+ return (
90
+ <input
91
+ type="number"
92
+ value={itemValue ?? ''}
93
+ onChange={(e) => {
94
+ const next = [...arr];
95
+ next[idx] =
96
+ e.target.value === '' ? undefined : Number(e.target.value);
97
+ onChange(next);
98
+ }}
99
+ className="input"
100
+ style={{ flex: 1 }}
101
+ />
102
+ );
103
+ case 'boolean':
104
+ case 'bool':
105
+ return (
106
+ <Checkbox
107
+ checked={Boolean(itemValue)}
108
+ onChange={(checked) => {
109
+ const next = [...arr];
110
+ next[idx] = checked;
111
+ onChange(next);
112
+ }}
113
+ name={`${name}-${idx}`}
114
+ />
115
+ );
116
+ case 'string':
117
+ return (
118
+ <input
119
+ type="text"
120
+ value={itemValue ?? ''}
121
+ onChange={(e) => {
122
+ const next = [...arr];
123
+ next[idx] =
124
+ e.target.value === '' ? undefined : e.target.value;
125
+ onChange(next);
126
+ }}
127
+ className="input"
128
+ style={{ flex: 1 }}
129
+ />
130
+ );
131
+ case 'color':
132
+ return (
133
+ <ColorPickerButton
134
+ value={typeof itemValue === 'string' ? itemValue : undefined}
135
+ onChange={(hex) => {
136
+ const next = [...arr];
137
+ next[idx] = hex;
138
+ onChange(next);
139
+ }}
140
+ projectColors={projectColors}
141
+ />
142
+ );
143
+ default:
144
+ return <p>---not-implemented----</p>;
145
+ }
146
+ };
147
+
148
+ return (
149
+ <div style={{ display: 'grid', gap: 8 }}>
150
+ {arr.map((item, idx) => (
151
+ <div
152
+ key={idx}
153
+ style={{ display: 'flex', gap: 8, alignItems: 'center' }}
154
+ >
155
+ {renderPrimitiveArrayItem(item, idx)}
156
+ <button
157
+ type="button"
158
+ onClick={() => {
159
+ const next = arr.filter((_, i) => i !== idx);
160
+ onChange(next.length ? next : undefined);
161
+ }}
162
+ >
163
+ remove
164
+ </button>
165
+ </div>
166
+ ))}
167
+ <div>
168
+ <button
169
+ type="button"
170
+ onClick={() => {
171
+ const next = [
172
+ ...arr,
173
+ itemType === 'boolean'
174
+ ? false
175
+ : itemType === 'number'
176
+ ? 0
177
+ : '',
178
+ ];
179
+ onChange(next);
180
+ }}
181
+ >
182
+ add
183
+ </button>
184
+ </div>
185
+ </div>
186
+ );
187
+ }
188
+
189
+ const schema = getTypeSchema(componentType, itemType) ?? {};
190
+ return (
191
+ <div style={{ display: 'grid', gap: 8 }}>
192
+ {arr.map((item, idx) => {
193
+ const obj = (item ?? {}) as Record<string, unknown>;
194
+ return (
195
+ <div
196
+ key={idx}
197
+ style={{ border: '1px solid #ddd', borderRadius: 6, padding: 8 }}
198
+ >
199
+ <div
200
+ style={{
201
+ display: 'grid',
202
+ gridTemplateColumns: '1fr 1fr',
203
+ gap: 8,
204
+ }}
205
+ >
206
+ {Object.entries(schema).map(([fieldName, fieldType]) => {
207
+ if (isBooleanFieldType(fieldType)) {
208
+ return (
209
+ <div key={fieldName} style={{ gridColumn: '1 / -1' }}>
210
+ <Field
211
+ name={fieldName}
212
+ type={fieldType}
213
+ value={obj?.[fieldName as keyof typeof obj]}
214
+ onChange={(val) => {
215
+ const next = [...arr];
216
+ const nextObj = {
217
+ ...(obj ?? {}),
218
+ [fieldName]: val,
219
+ };
220
+ next[idx] = nextObj;
221
+ onChange(next);
222
+ }}
223
+ componentType={componentType}
224
+ projectColors={projectColors}
225
+ layoutContext={layoutContext}
226
+ viewAttributes={viewAttributes}
227
+ label={fieldName}
228
+ />
229
+ </div>
230
+ );
231
+ }
232
+ return (
233
+ <React.Fragment key={fieldName}>
234
+ <div style={{ alignSelf: 'center' }}>{fieldName}</div>
235
+ <Field
236
+ name={fieldName}
237
+ type={fieldType}
238
+ value={obj?.[fieldName as keyof typeof obj]}
239
+ onChange={(val) => {
240
+ const next = [...arr];
241
+ const nextObj = { ...(obj ?? {}), [fieldName]: val };
242
+ next[idx] = nextObj;
243
+ onChange(next);
244
+ }}
245
+ componentType={componentType}
246
+ projectColors={projectColors}
247
+ layoutContext={layoutContext}
248
+ viewAttributes={viewAttributes}
249
+ />
250
+ </React.Fragment>
251
+ );
252
+ })}
253
+ </div>
254
+ <div style={{ marginTop: 8 }}>
255
+ <button
256
+ type="button"
257
+ onClick={() => {
258
+ const next = arr.filter((_, i) => i !== idx);
259
+ onChange(next.length ? next : undefined);
260
+ }}
261
+ >
262
+ remove
263
+ </button>
264
+ </div>
265
+ </div>
266
+ );
267
+ })}
268
+ <div>
269
+ <button
270
+ type="button"
271
+ onClick={() => {
272
+ const empty: Record<string, unknown> = {};
273
+ const next = [...arr, empty];
274
+ onChange(next);
275
+ }}
276
+ >
277
+ add
278
+ </button>
279
+ </div>
280
+ </div>
281
+ );
282
+ }
283
+
284
+ if (typeof type === 'string' && !isPrimitiveType(type)) {
285
+ const schema = getTypeSchema(componentType, type);
286
+ if (schema) {
287
+ const obj = (value ?? {}) as Record<string, unknown>;
288
+ return (
289
+ <div
290
+ style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 8 }}
291
+ >
292
+ {Object.entries(schema).map(([fieldName, fieldType]) => {
293
+ if (isBooleanFieldType(fieldType)) {
294
+ return (
295
+ <div key={fieldName} style={{ gridColumn: '1 / -1' }}>
296
+ <Field
297
+ name={fieldName}
298
+ type={fieldType}
299
+ value={obj?.[fieldName as keyof typeof obj]}
300
+ onChange={(val) => {
301
+ const nextObj = { ...(obj ?? {}), [fieldName]: val };
302
+ onChange(nextObj);
303
+ }}
304
+ componentType={componentType}
305
+ projectColors={projectColors}
306
+ layoutContext={layoutContext}
307
+ viewAttributes={viewAttributes}
308
+ label={fieldName}
309
+ />
310
+ </div>
311
+ );
312
+ }
313
+ return (
314
+ <React.Fragment key={fieldName}>
315
+ <div style={{ alignSelf: 'center' }}>{fieldName}</div>
316
+ <Field
317
+ name={fieldName}
318
+ type={fieldType}
319
+ value={obj?.[fieldName as keyof typeof obj]}
320
+ onChange={(val) => {
321
+ const nextObj = { ...(obj ?? {}), [fieldName]: val };
322
+ onChange(nextObj);
323
+ }}
324
+ componentType={componentType}
325
+ projectColors={projectColors}
326
+ layoutContext={layoutContext}
327
+ viewAttributes={viewAttributes}
328
+ />
329
+ </React.Fragment>
330
+ );
331
+ })}
332
+ </div>
333
+ );
334
+ }
335
+ }
336
+
337
+ if (type === 'string[]') {
338
+ const arr: string[] = Array.isArray(value) ? value : [];
339
+ return (
340
+ <div style={{ display: 'grid', gap: 8 }}>
341
+ {arr.map((item, idx) => (
342
+ <div
343
+ key={idx}
344
+ style={{ display: 'flex', gap: 8, alignItems: 'center' }}
345
+ >
346
+ <input
347
+ type="text"
348
+ value={item ?? ''}
349
+ onChange={(e) => {
350
+ const next = [...arr];
351
+ next[idx] = e.target.value;
352
+ onChange(next);
353
+ }}
354
+ className="input"
355
+ style={{ flex: 1 }}
356
+ />
357
+ <button
358
+ type="button"
359
+ onClick={() => {
360
+ const next = arr.filter((_, i) => i !== idx);
361
+ onChange(next.length ? next : undefined);
362
+ }}
363
+ >
364
+ remove
365
+ </button>
366
+ </div>
367
+ ))}
368
+ <div>
369
+ <button
370
+ type="button"
371
+ onClick={() => {
372
+ const next = [...arr, ''];
373
+ onChange(next);
374
+ }}
375
+ >
376
+ add
377
+ </button>
378
+ </div>
379
+ </div>
380
+ );
381
+ }
382
+
383
+ if (typeof type !== 'string') {
384
+ return <p>---not-implemented----</p>;
385
+ }
386
+
387
+ switch (type) {
388
+ case 'size':
389
+ return (
390
+ <SizeField
391
+ value={value}
392
+ onChange={onChange}
393
+ preferredScale={preferredScale}
394
+ fieldName={name}
395
+ />
396
+ );
397
+ case 'number':
398
+ return (
399
+ <input
400
+ type="number"
401
+ value={value ?? ''}
402
+ onChange={(e) =>
403
+ onChange(e.target.value === '' ? undefined : Number(e.target.value))
404
+ }
405
+ className="input"
406
+ />
407
+ );
408
+ case 'boolean':
409
+ case 'bool':
410
+ return (
411
+ <Checkbox
412
+ label={label ?? name}
413
+ checked={Boolean(value)}
414
+ onChange={(checked) => onChange(checked)}
415
+ name={name}
416
+ />
417
+ );
418
+ case 'string':
419
+ return (
420
+ <input
421
+ type="text"
422
+ value={value ?? ''}
423
+ onChange={(e) =>
424
+ onChange(e.target.value === '' ? undefined : e.target.value)
425
+ }
426
+ className="input"
427
+ />
428
+ );
429
+ case 'color':
430
+ return (
431
+ <ColorPickerButton
432
+ value={typeof value === 'string' ? value : undefined}
433
+ onChange={(hex) => onChange(hex)}
434
+ projectColors={projectColors}
435
+ />
436
+ );
437
+ default:
438
+ return <p>---not-implemented----</p>;
439
+ }
440
+ }
441
+
442
+ type ColorPickerButtonProps = {
443
+ value?: string;
444
+ onChange: (color?: string) => void;
445
+ projectColors?: ProjectColors;
446
+ };
447
+
448
+ function ColorPickerButton({
449
+ value,
450
+ onChange,
451
+ projectColors,
452
+ }: ColorPickerButtonProps) {
453
+ const [isOpen, setIsOpen] = useState(false);
454
+ const normalizedValue = typeof value === 'string' ? value : undefined;
455
+ const previewColor = useMemo(
456
+ () =>
457
+ resolveProjectColorValue(normalizedValue, projectColors) ??
458
+ normalizedValue,
459
+ [normalizedValue, projectColors],
460
+ );
461
+
462
+ return (
463
+ <>
464
+ <button
465
+ type="button"
466
+ onClick={() => setIsOpen(true)}
467
+ style={{
468
+ width: '100%',
469
+ display: 'flex',
470
+ alignItems: 'center',
471
+ justifyContent: 'space-between',
472
+ gap: 8,
473
+ borderRadius: 6,
474
+ border: '1px solid #ddd',
475
+ padding: '8px 10px',
476
+ background: '#fff',
477
+ cursor: 'pointer',
478
+ }}
479
+ >
480
+ <span
481
+ aria-hidden
482
+ style={{
483
+ width: 32,
484
+ height: 32,
485
+ borderRadius: 6,
486
+ border: '1px solid rgba(0,0,0,0.1)',
487
+ background: previewColor ?? 'transparent',
488
+ }}
489
+ />
490
+ <span style={{ flex: 1, textAlign: 'left', fontWeight: 500 }}>
491
+ {normalizedValue ?? 'Select color'}
492
+ </span>
493
+ <span style={{ fontSize: 12, color: '#666' }}>Open</span>
494
+ </button>
495
+ {isOpen ? (
496
+ <ColorModal
497
+ value={normalizedValue}
498
+ projectColors={projectColors}
499
+ onSelect={(hex) => {
500
+ onChange(hex);
501
+ setIsOpen(false);
502
+ }}
503
+ onClose={() => setIsOpen(false)}
504
+ onClear={() => {
505
+ onChange(undefined);
506
+ setIsOpen(false);
507
+ }}
508
+ />
509
+ ) : null}
510
+ </>
511
+ );
512
+ }
513
+
514
+ type SizeUnit = '' | 'vs' | 's' | 'f' | '%';
515
+
516
+ function parseSizeValue(value: unknown): { amount: string; unit: SizeUnit } {
517
+ const empty = { amount: '', unit: '' as SizeUnit };
518
+ if (typeof value === 'number' && Number.isFinite(value)) {
519
+ return { amount: String(value), unit: '' };
520
+ }
521
+ if (typeof value !== 'string') return empty;
522
+ const trimmed = value.trim();
523
+ if (!trimmed) return empty;
524
+ if (trimmed.endsWith('%')) {
525
+ return { amount: trimmed.slice(0, -1), unit: '%' };
526
+ }
527
+ const lower = trimmed.toLowerCase();
528
+ if (lower.endsWith('@vs'))
529
+ return { amount: trimmed.slice(0, -3), unit: 'vs' };
530
+ if (lower.endsWith('vs')) return { amount: trimmed.slice(0, -2), unit: 'vs' };
531
+ if (lower.endsWith('@fs')) return { amount: trimmed.slice(0, -3), unit: 'f' };
532
+ if (lower.endsWith('@f')) return { amount: trimmed.slice(0, -2), unit: 'f' };
533
+ if (lower.endsWith('fs')) return { amount: trimmed.slice(0, -2), unit: 'f' };
534
+ if (lower.endsWith('f')) return { amount: trimmed.slice(0, -1), unit: 'f' };
535
+ if (lower.endsWith('@s')) return { amount: trimmed.slice(0, -2), unit: 's' };
536
+ if (lower.endsWith('s')) return { amount: trimmed.slice(0, -1), unit: 's' };
537
+ if (lower.endsWith('px')) return { amount: trimmed.slice(0, -2), unit: '' };
538
+ return { amount: trimmed, unit: '' };
539
+ }
540
+
541
+ function composeSizeValue(amount: string, unit: SizeUnit): string | number {
542
+ const trimmed = amount.trim();
543
+ if (unit === '%') {
544
+ return `${trimmed}%`;
545
+ }
546
+ if (unit === '') {
547
+ const numeric = Number(trimmed);
548
+ return Number.isFinite(numeric) ? numeric : trimmed;
549
+ }
550
+ if (unit === 'f') {
551
+ return `${trimmed}@fs`;
552
+ }
553
+ return `${trimmed}@${unit}`;
554
+ }
555
+
556
+ type SizeFieldProps = {
557
+ value: unknown;
558
+ onChange: (val: unknown) => void;
559
+ preferredScale?: string;
560
+ fieldName: string;
561
+ };
562
+
563
+ function normalizePreferredScale(
564
+ preferredScale: string | undefined,
565
+ fieldName: string,
566
+ ): SizeUnit {
567
+ const fallbackName = fieldName.trim().toLowerCase();
568
+ const fallback: SizeUnit =
569
+ fallbackName.includes('height') ||
570
+ fallbackName.includes('top') ||
571
+ fallbackName.includes('vertical')
572
+ ? 'vs'
573
+ : 's';
574
+ if (typeof preferredScale !== 'string') return fallback;
575
+ const normalized = preferredScale.trim().toLowerCase();
576
+ if (
577
+ normalized === 'vs' ||
578
+ normalized === 's' ||
579
+ normalized === 'f' ||
580
+ normalized === '%'
581
+ ) {
582
+ return normalized as SizeUnit;
583
+ }
584
+ return fallback;
585
+ }
586
+
587
+ function SizeField({
588
+ value,
589
+ onChange,
590
+ preferredScale,
591
+ fieldName,
592
+ }: SizeFieldProps) {
593
+ const parsed = useMemo(() => parseSizeValue(value), [value]);
594
+ const normalizedPreferred = useMemo(
595
+ () => normalizePreferredScale(preferredScale, fieldName),
596
+ [preferredScale, fieldName],
597
+ );
598
+ const [amount, setAmount] = useState(parsed.amount);
599
+ const [unit, setUnit] = useState<SizeUnit>(
600
+ parsed.unit || normalizedPreferred,
601
+ );
602
+
603
+ useEffect(() => {
604
+ setAmount(parsed.amount);
605
+ setUnit(parsed.unit || normalizedPreferred);
606
+ }, [parsed.amount, parsed.unit, normalizedPreferred]);
607
+
608
+ const emitValue = useCallback(
609
+ (nextAmount: string, nextUnit: SizeUnit) => {
610
+ const trimmed = nextAmount.trim();
611
+ if (!trimmed) {
612
+ onChange(undefined);
613
+ return;
614
+ }
615
+ onChange(composeSizeValue(trimmed, nextUnit));
616
+ },
617
+ [onChange],
618
+ );
619
+
620
+ const handleAmountChange = (e: React.ChangeEvent<HTMLInputElement>) => {
621
+ const nextAmount = e.target.value;
622
+ setAmount(nextAmount);
623
+ if (!nextAmount.trim()) {
624
+ onChange(undefined);
625
+ return;
626
+ }
627
+ emitValue(nextAmount, unit);
628
+ };
629
+
630
+ const handleUnitChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
631
+ const nextUnit = e.target.value as SizeUnit;
632
+ setUnit(nextUnit);
633
+ if (!amount.trim()) return;
634
+ emitValue(amount, nextUnit);
635
+ };
636
+
637
+ const unitPriority: SizeUnit[] = ['vs', 's', 'f', '%'];
638
+ const orderedUnits = [
639
+ normalizedPreferred,
640
+ ...unitPriority.filter((unit) => unit !== normalizedPreferred),
641
+ ];
642
+ const unitOptions: Array<{ value: SizeUnit; label: string }> =
643
+ orderedUnits.map((unit) => ({
644
+ value: unit,
645
+ label: unit === normalizedPreferred ? `${unit}` : unit,
646
+ }));
647
+
648
+ return (
649
+ <div className="attributes-editor__size-field">
650
+ <input
651
+ type="number"
652
+ className="input attributes-editor__size-field-input"
653
+ value={amount}
654
+ onChange={handleAmountChange}
655
+ />
656
+ <select
657
+ className="input attributes-editor__size-field-select"
658
+ value={unit}
659
+ onChange={handleUnitChange}
660
+ >
661
+ {unitOptions.map((opt) => (
662
+ <option key={opt.value} value={opt.value}>
663
+ {opt.label}
664
+ </option>
665
+ ))}
666
+ </select>
667
+ </div>
668
+ );
669
+ }
@@ -0,0 +1,49 @@
1
+ import React, { useState } from 'react';
2
+
3
+ type FieldInfoTooltipProps = {
4
+ description?: string;
5
+ children: React.ReactNode;
6
+ };
7
+
8
+ export function FieldInfoTooltip({
9
+ description,
10
+ children,
11
+ }: FieldInfoTooltipProps) {
12
+ const [isHovered, setIsHovered] = useState(false);
13
+
14
+ if (!description || !description.trim()) {
15
+ return <>{children}</>;
16
+ }
17
+
18
+ const bubbleClassName = [
19
+ 'field-info-tooltip__bubble',
20
+ isHovered ? 'field-info-tooltip__bubble--visible' : '',
21
+ ]
22
+ .filter(Boolean)
23
+ .join(' ');
24
+ const handleShow = () => setIsHovered(true);
25
+ const handleHide = () => setIsHovered(false);
26
+
27
+ return (
28
+ <div className="field-info-tooltip">
29
+ {children}
30
+ <button
31
+ className="field-info-tooltip__trigger"
32
+ onMouseEnter={handleShow}
33
+ onMouseLeave={handleHide}
34
+ onFocus={handleShow}
35
+ onBlur={handleHide}
36
+ type="button"
37
+ >
38
+ Show info
39
+ <span
40
+ className={bubbleClassName}
41
+ role="tooltip"
42
+ aria-hidden={!isHovered}
43
+ >
44
+ {description}
45
+ </span>
46
+ </button>
47
+ </div>
48
+ );
49
+ }