@adea-ai/app-framework 0.43.0 → 0.44.1

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.
@@ -24,11 +24,6 @@ export type AppearanceContextValue = Omit<UiThemeContextValue, 'preview'> & {
24
24
  export declare function appearanceProviderProps(options?: {
25
25
  nativeTranslucency?: () => boolean;
26
26
  }): Omit<UiThemeProviderProps, 'children'>;
27
- /**
28
- * The V2 view of a shared theme context. Reads derive from the provider's selection;
29
- * writes go through its `setSelection`, so the shared provider remains the only
30
- * writer of the document and of storage.
31
- */
32
27
  export declare function createAppearanceContext(ui: UiThemeContextValue): AppearanceContextValue;
33
28
  type ThemeProviderProps = ParentProps<{
34
29
  /**
@@ -56,15 +56,21 @@ function projectCachedTokens(tokens, rules) {
56
56
  * writes go through its `setSelection`, so the shared provider remains the only
57
57
  * writer of the document and of storage.
58
58
  */
59
+ function previewSelection(value) {
60
+ return selectionFromPreferences({
61
+ ...value,
62
+ codeThemeId: value.codeThemeId ?? "theme"
63
+ });
64
+ }
59
65
  function createAppearanceContext(ui) {
60
66
  let draft;
61
67
  const preview = (next) => {
62
68
  draft = next;
63
- ui.preview(next ? selectionFromPreferences(next) : void 0);
69
+ ui.preview(next ? previewSelection(next) : void 0);
64
70
  };
65
71
  createEffect(() => {
66
72
  ui.selection();
67
- if (draft !== void 0 && !ui.previewing()) ui.preview(selectionFromPreferences(draft));
73
+ if (draft !== void 0 && !ui.previewing()) ui.preview(previewSelection(draft));
68
74
  });
69
75
  return {
70
76
  ...ui,
@@ -19,6 +19,13 @@ export type AppearancePreferencesV2 = Readonly<{
19
19
  * theme id pins that theme's terminal colours regardless of appearance.
20
20
  */
21
21
  terminalThemeId: 'theme' | string;
22
+ /**
23
+ * Code's palette (editor, diff and file views), on the terminal's rule: `'theme'`
24
+ * follows the resolved interface theme, a theme id pins that theme's syntax
25
+ * colours and code canvas. Optional like `fonts`: absent reads as `'theme'`, and
26
+ * a document that never chose one is rewritten without the key.
27
+ */
28
+ codeThemeId?: 'theme' | string;
22
29
  /** A built-in preset id, a theme-carried `ansi-<slot>` id, or a validated `#rrggbb` color. `'theme'` normalizes to the default preset. */
23
30
  accent: 'theme' | string;
24
31
  surface: SurfacePreference;
@@ -76,6 +76,7 @@ function normalizeAppearancePreferences(raw) {
76
76
  lightThemeId: normalizeThemeId(record.lightThemeId, defaultAppearancePreferences.lightThemeId),
77
77
  darkThemeId: normalizeThemeId(record.darkThemeId, defaultAppearancePreferences.darkThemeId),
78
78
  terminalThemeId: normalizeThemeId(record.terminalThemeId, "theme"),
79
+ ...record.codeThemeId === void 0 ? {} : { codeThemeId: normalizeThemeId(record.codeThemeId, "theme") },
79
80
  accent: normalizeAccent(record.accent),
80
81
  surface: normalizeSurface$1(record.surface),
81
82
  reduceTransparency: record.reduceTransparency === true,
@@ -92,6 +93,7 @@ function selectionFromPreferences(preferences) {
92
93
  ...preferences.lightThemeId === void 0 ? {} : { lightThemeId: preferences.lightThemeId },
93
94
  ...preferences.darkThemeId === void 0 ? {} : { darkThemeId: preferences.darkThemeId },
94
95
  ...preferences.terminalThemeId === void 0 ? {} : { terminalThemeId: preferences.terminalThemeId },
96
+ ...preferences.codeThemeId === void 0 ? {} : { codeThemeId: preferences.codeThemeId },
95
97
  ...preferences.accent === void 0 ? {} : { accent: preferences.accent === "theme" ? DEFAULT_ACCENT_PRESET_ID : preferences.accent },
96
98
  ...preferences.surface === void 0 ? {} : { surface: preferences.surface },
97
99
  ...preferences.reduceTransparency === void 0 ? {} : { reduceTransparency: preferences.reduceTransparency },
@@ -109,9 +111,14 @@ function preferencesFromSelection(selection) {
109
111
  accent: selection.accent === "theme" ? DEFAULT_ACCENT_PRESET_ID : selection.accent,
110
112
  surface: selection.surface ?? "opaque",
111
113
  reduceTransparency: selection.reduceTransparency === true,
114
+ ...codeThemeIdOf(selection) === void 0 ? {} : { codeThemeId: codeThemeIdOf(selection) },
112
115
  ...selection.fonts === void 0 ? {} : { fonts: selection.fonts }
113
116
  };
114
117
  }
118
+ /** The selection's code pin; read loosely so an older `@adea-ai/ui` still type-checks. */
119
+ function codeThemeIdOf(selection) {
120
+ return selection.codeThemeId;
121
+ }
115
122
  function sameFonts(left, right) {
116
123
  return [
117
124
  "ui",
@@ -14,6 +14,7 @@ var scalarFields = Object.keys({
14
14
  function samePreferences(left, right) {
15
15
  if (left === right) return true;
16
16
  if (!scalarFields.every((field) => left[field] === right[field])) return false;
17
+ if ((left.codeThemeId ?? "theme") !== (right.codeThemeId ?? "theme")) return false;
17
18
  if (left.fonts === right.fonts) return true;
18
19
  const leftFonts = normalizeAppearanceEditorFontSettings(left.fonts).settings;
19
20
  const rightFonts = normalizeAppearanceEditorFontSettings(right.fonts).settings;
@@ -57,9 +58,13 @@ function createAppearanceEditor(committed = defaultAppearancePreferences) {
57
58
  merge: (current) => {
58
59
  const before = snapshot();
59
60
  const after = draft();
60
- if (resetAll()) return after;
61
+ if (resetAll()) return {
62
+ ...after,
63
+ ...current.codeThemeId === void 0 ? {} : { codeThemeId: after.codeThemeId ?? "theme" }
64
+ };
61
65
  const merged = { ...current };
62
66
  for (const field of scalarFields) if (before[field] !== after[field]) Object.assign(merged, { [field]: after[field] });
67
+ if ((before.codeThemeId ?? "theme") !== (after.codeThemeId ?? "theme")) merged.codeThemeId = after.codeThemeId ?? "theme";
63
68
  const originalFonts = normalizeAppearanceEditorFontSettings(before.fonts).settings;
64
69
  const draftFonts = normalizeAppearanceEditorFontSettings(after.fonts).settings;
65
70
  const currentFonts = normalizeAppearanceEditorFontSettings(current.fonts).settings;
@@ -1 +1 @@
1
- {"version":"0.43.0","commit":"cdc9302751506a068d49f0beb7f20e8c1bce9eb2"}
1
+ {"version":"0.44.1","commit":"5b23d0416a45130ae5cdfd90f9878f6ca7e921e5"}
@@ -135,7 +135,8 @@ function AppearanceHost(props) {
135
135
  return {
136
136
  ...draft,
137
137
  accent: rawCustomAccent() && !getAccent(draft.accent) && !isThemeAccentId(draft.accent) && draft.accent !== "theme" ? rawCustomAccent() : draft.accent,
138
- surface: draft.surface === "translucent" ? "theme" : draft.surface
138
+ surface: draft.surface === "translucent" ? "theme" : draft.surface,
139
+ codeThemeId: draft.codeThemeId ?? "theme"
139
140
  };
140
141
  });
141
142
  const sampleVariant = () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adea-ai/app-framework",
3
- "version": "0.43.0",
3
+ "version": "0.44.1",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -126,19 +126,23 @@ function projectCachedTokens(
126
126
  * writes go through its `setSelection`, so the shared provider remains the only
127
127
  * writer of the document and of storage.
128
128
  */
129
+ function previewSelection(value: AppearancePreferencesV2) {
130
+ return selectionFromPreferences({ ...value, codeThemeId: value.codeThemeId ?? 'theme' })
131
+ }
132
+
129
133
  export function createAppearanceContext(ui: UiThemeContextValue): AppearanceContextValue {
130
134
  let draft: AppearancePreferencesV2 | undefined
131
135
 
132
136
  const preview = (next: AppearancePreferencesV2 | undefined) => {
133
137
  draft = next
134
- ui.preview(next ? selectionFromPreferences(next) : undefined)
138
+ ui.preview(next ? previewSelection(next) : undefined)
135
139
  }
136
140
 
137
141
  // The shared provider ends a preview when the selection is committed. The editor's
138
142
  // draft is still open, though, so it keeps showing until the editor ends it.
139
143
  createEffect(() => {
140
144
  ui.selection()
141
- if (draft !== undefined && !ui.previewing()) ui.preview(selectionFromPreferences(draft))
145
+ if (draft !== undefined && !ui.previewing()) ui.preview(previewSelection(draft))
142
146
  })
143
147
 
144
148
  return {
@@ -49,6 +49,13 @@ export type AppearancePreferencesV2 = Readonly<{
49
49
  * theme id pins that theme's terminal colours regardless of appearance.
50
50
  */
51
51
  terminalThemeId: 'theme' | string
52
+ /**
53
+ * Code's palette (editor, diff and file views), on the terminal's rule: `'theme'`
54
+ * follows the resolved interface theme, a theme id pins that theme's syntax
55
+ * colours and code canvas. Optional like `fonts`: absent reads as `'theme'`, and
56
+ * a document that never chose one is rewritten without the key.
57
+ */
58
+ codeThemeId?: 'theme' | string
52
59
  /** A built-in preset id, a theme-carried `ansi-<slot>` id, or a validated `#rrggbb` color. `'theme'` normalizes to the default preset. */
53
60
  accent: 'theme' | string
54
61
  surface: SurfacePreference
@@ -154,6 +161,9 @@ export function normalizeAppearancePreferences(raw: unknown): NormalizedPreferen
154
161
  ),
155
162
  darkThemeId: normalizeThemeId(record.darkThemeId, defaultAppearancePreferences.darkThemeId),
156
163
  terminalThemeId: normalizeThemeId(record.terminalThemeId, 'theme'),
164
+ ...(record.codeThemeId === undefined
165
+ ? {}
166
+ : { codeThemeId: normalizeThemeId(record.codeThemeId, 'theme') }),
157
167
  accent: normalizeAccent(record.accent),
158
168
  surface: normalizeSurface(record.surface),
159
169
  reduceTransparency: record.reduceTransparency === true,
@@ -183,6 +193,7 @@ export function selectionFromPreferences(
183
193
  ...(preferences.terminalThemeId === undefined
184
194
  ? {}
185
195
  : { terminalThemeId: preferences.terminalThemeId }),
196
+ ...(preferences.codeThemeId === undefined ? {} : { codeThemeId: preferences.codeThemeId }),
186
197
  // `'theme'` is the default preset everywhere a draft, a
187
198
  // stored record or a direct update can reach: the provider's own `theme` means
188
199
  // "the variant's primary", which no V2 preference can select.
@@ -210,10 +221,16 @@ export function preferencesFromSelection(selection: ThemeSelection): AppearanceP
210
221
  accent: selection.accent === 'theme' ? DEFAULT_ACCENT_PRESET_ID : selection.accent,
211
222
  surface: selection.surface ?? 'opaque',
212
223
  reduceTransparency: selection.reduceTransparency === true,
224
+ ...(codeThemeIdOf(selection) === undefined ? {} : { codeThemeId: codeThemeIdOf(selection) }),
213
225
  ...(selection.fonts === undefined ? {} : { fonts: selection.fonts }),
214
226
  }
215
227
  }
216
228
 
229
+ /** The selection's code pin; read loosely so an older `@adea-ai/ui` still type-checks. */
230
+ function codeThemeIdOf(selection: ThemeSelection): string | undefined {
231
+ return (selection as ThemeSelection & { codeThemeId?: string }).codeThemeId
232
+ }
233
+
217
234
  function sameFonts(left: AppearanceEditorFontSettings, right: AppearanceEditorFontSettings) {
218
235
  return (['ui', 'content', 'code'] as const).every(
219
236
  (axis) => left[axis].family === right[axis].family && left[axis].size === right[axis].size
@@ -41,7 +41,7 @@ export type AppearanceEditor = Readonly<{
41
41
  save: () => AppearancePreferencesV2
42
42
  }>
43
43
 
44
- type ScalarPreference = Exclude<keyof AppearancePreferencesV2, 'version' | 'fonts'>
44
+ type ScalarPreference = Exclude<keyof AppearancePreferencesV2, 'version' | 'fonts' | 'codeThemeId'>
45
45
  // Record exhaustiveness makes a newly added scalar preference require a merge policy.
46
46
  const scalarFields = Object.keys({
47
47
  mode: true,
@@ -56,6 +56,7 @@ const scalarFields = Object.keys({
56
56
  function samePreferences(left: AppearancePreferencesV2, right: AppearancePreferencesV2): boolean {
57
57
  if (left === right) return true
58
58
  if (!scalarFields.every((field) => left[field] === right[field])) return false
59
+ if ((left.codeThemeId ?? 'theme') !== (right.codeThemeId ?? 'theme')) return false
59
60
  if (left.fonts === right.fonts) return true
60
61
  const leftFonts = normalizeAppearanceEditorFontSettings(left.fonts).settings
61
62
  const rightFonts = normalizeAppearanceEditorFontSettings(right.fonts).settings
@@ -101,11 +102,20 @@ export function createAppearanceEditor(
101
102
  merge: (current) => {
102
103
  const before = snapshot()
103
104
  const after = draft()
104
- if (resetAll()) return after
105
+ if (resetAll())
106
+ return {
107
+ ...after,
108
+ ...(current.codeThemeId === undefined
109
+ ? {}
110
+ : { codeThemeId: after.codeThemeId ?? 'theme' }),
111
+ }
105
112
  const merged = { ...current }
106
113
  for (const field of scalarFields) {
107
114
  if (before[field] !== after[field]) Object.assign(merged, { [field]: after[field] })
108
115
  }
116
+ // Optional like `fonts`: merged only when the draft changed it.
117
+ if ((before.codeThemeId ?? 'theme') !== (after.codeThemeId ?? 'theme'))
118
+ merged.codeThemeId = after.codeThemeId ?? 'theme'
109
119
  const originalFonts = normalizeAppearanceEditorFontSettings(before.fonts).settings
110
120
  const draftFonts = normalizeAppearanceEditorFontSettings(after.fonts).settings
111
121
  const currentFonts = normalizeAppearanceEditorFontSettings(current.fonts).settings
@@ -221,6 +221,8 @@ function AppearanceHost(props: { popover?: AppearanceControlProps }) {
221
221
  ? rawCustomAccent()
222
222
  : draft.accent,
223
223
  surface: draft.surface === 'translucent' ? 'theme' : draft.surface,
224
+ // Always present, so the editor shows its Code row: absent means "follow the UI".
225
+ codeThemeId: draft.codeThemeId ?? 'theme',
224
226
  }
225
227
  })
226
228