datocms-plugin-sdk 2.1.1 → 3.0.1-alpha.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/manifest.json CHANGED
@@ -3109,13 +3109,34 @@
3109
3109
  },
3110
3110
  "theme": {
3111
3111
  "comment": {
3112
- "markdownText": "An object containing the theme colors for the current DatoCMS project."
3112
+ "markdownText": "An object containing the theme colors for the current DatoCMS project.",
3113
+ "deprecatedMarkdownText": "Use `semanticColorTokensTheme` instead. This property is kept\nfor backward compatibility with third-party plugins."
3113
3114
  },
3114
3115
  "location": {
3115
3116
  "filePath": "src/ctx/base.ts",
3116
- "lineNumber": 87
3117
+ "lineNumber": 92
3117
3118
  },
3118
3119
  "type": "Theme"
3120
+ },
3121
+ "semanticColorTokensTheme": {
3122
+ "comment": {
3123
+ "markdownText": "Semantic color tokens for the current DatoCMS project, pre-computed by\nthe host. Only available on DatoCMS hosts that support the new token\nsystem."
3124
+ },
3125
+ "location": {
3126
+ "filePath": "src/ctx/base.ts",
3127
+ "lineNumber": 99
3128
+ },
3129
+ "type": "SemanticColorTokensTheme"
3130
+ },
3131
+ "colorScheme": {
3132
+ "comment": {
3133
+ "markdownText": "The appearance color scheme the host CMS is currently using. Resolved —\n`'system'` is already expanded to `'light'` or `'dark'` by the host.\n\nThe SDK runtime reflects this onto `document.documentElement` as\n`data-theme=\"light\"` / `data-theme=\"dark\"` so plugin CSS can branch\nwith `[data-theme=\"dark\"] { … }` selectors. For non-CSS decisions\n(choosing a logo asset, a syntax-highlighting preset, …) branch on\n`ctx.colorScheme` directly."
3134
+ },
3135
+ "location": {
3136
+ "filePath": "src/ctx/base.ts",
3137
+ "lineNumber": 111
3138
+ },
3139
+ "type": "'light' | 'dark'"
3119
3140
  }
3120
3141
  }
3121
3142
  },
@@ -3131,7 +3152,7 @@
3131
3152
  },
3132
3153
  "location": {
3133
3154
  "filePath": "src/ctx/base.ts",
3134
- "lineNumber": 97
3155
+ "lineNumber": 121
3135
3156
  },
3136
3157
  "type": "Partial<Record<string, ItemType>>"
3137
3158
  },
@@ -3141,7 +3162,7 @@
3141
3162
  },
3142
3163
  "location": {
3143
3164
  "filePath": "src/ctx/base.ts",
3144
- "lineNumber": 104
3165
+ "lineNumber": 128
3145
3166
  },
3146
3167
  "type": "Partial<Record<string, Field>>"
3147
3168
  },
@@ -3151,7 +3172,7 @@
3151
3172
  },
3152
3173
  "location": {
3153
3174
  "filePath": "src/ctx/base.ts",
3154
- "lineNumber": 111
3175
+ "lineNumber": 135
3155
3176
  },
3156
3177
  "type": "Partial<Record<string, Fieldset>>"
3157
3178
  },
@@ -3161,7 +3182,7 @@
3161
3182
  },
3162
3183
  "location": {
3163
3184
  "filePath": "src/ctx/base.ts",
3164
- "lineNumber": 118
3185
+ "lineNumber": 142
3165
3186
  },
3166
3187
  "type": "Partial<Record<string, User>>"
3167
3188
  },
@@ -3171,7 +3192,7 @@
3171
3192
  },
3172
3193
  "location": {
3173
3194
  "filePath": "src/ctx/base.ts",
3174
- "lineNumber": 125
3195
+ "lineNumber": 149
3175
3196
  },
3176
3197
  "type": "Partial<Record<string, SsoUser>>"
3177
3198
  }
@@ -3192,7 +3213,7 @@
3192
3213
  },
3193
3214
  "location": {
3194
3215
  "filePath": "src/ctx/base.ts",
3195
- "lineNumber": 168
3216
+ "lineNumber": 353
3196
3217
  },
3197
3218
  "type": "(itemTypeId: string) => Promise<Field[]>"
3198
3219
  },
@@ -3203,7 +3224,7 @@
3203
3224
  },
3204
3225
  "location": {
3205
3226
  "filePath": "src/ctx/base.ts",
3206
- "lineNumber": 187
3227
+ "lineNumber": 372
3207
3228
  },
3208
3229
  "type": "(itemTypeId: string) => Promise<Fieldset[]>"
3209
3230
  },
@@ -3214,7 +3235,7 @@
3214
3235
  },
3215
3236
  "location": {
3216
3237
  "filePath": "src/ctx/base.ts",
3217
- "lineNumber": 204
3238
+ "lineNumber": 389
3218
3239
  },
3219
3240
  "type": "() => Promise<Field[]>"
3220
3241
  },
@@ -3225,7 +3246,7 @@
3225
3246
  },
3226
3247
  "location": {
3227
3248
  "filePath": "src/ctx/base.ts",
3228
- "lineNumber": 217
3249
+ "lineNumber": 402
3229
3250
  },
3230
3251
  "type": "() => Promise<User[]>"
3231
3252
  },
@@ -3236,7 +3257,7 @@
3236
3257
  },
3237
3258
  "location": {
3238
3259
  "filePath": "src/ctx/base.ts",
3239
- "lineNumber": 230
3260
+ "lineNumber": 415
3240
3261
  },
3241
3262
  "type": "() => Promise<SsoUser[]>"
3242
3263
  }
@@ -3255,7 +3276,7 @@
3255
3276
  },
3256
3277
  "location": {
3257
3278
  "filePath": "src/ctx/base.ts",
3258
- "lineNumber": 252
3279
+ "lineNumber": 437
3259
3280
  },
3260
3281
  "type": "(params: Record<string, unknown>) => Promise<void>"
3261
3282
  },
@@ -3266,7 +3287,7 @@
3266
3287
  },
3267
3288
  "location": {
3268
3289
  "filePath": "src/ctx/base.ts",
3269
- "lineNumber": 303
3290
+ "lineNumber": 488
3270
3291
  },
3271
3292
  "type": "(\n fieldId: string,\n changes: FieldAppearanceChange[],\n ) => Promise<void>"
3272
3293
  }
@@ -3285,7 +3306,7 @@
3285
3306
  },
3286
3307
  "location": {
3287
3308
  "filePath": "src/ctx/base.ts",
3288
- "lineNumber": 408
3309
+ "lineNumber": 593
3289
3310
  },
3290
3311
  "type": "(message: string) => Promise<void>"
3291
3312
  },
@@ -3296,7 +3317,7 @@
3296
3317
  },
3297
3318
  "location": {
3298
3319
  "filePath": "src/ctx/base.ts",
3299
- "lineNumber": 423
3320
+ "lineNumber": 608
3300
3321
  },
3301
3322
  "type": "(message: string) => Promise<void>"
3302
3323
  },
@@ -3307,7 +3328,7 @@
3307
3328
  },
3308
3329
  "location": {
3309
3330
  "filePath": "src/ctx/base.ts",
3310
- "lineNumber": 447
3331
+ "lineNumber": 632
3311
3332
  },
3312
3333
  "type": "<CtaValue = unknown>(\n toast: Toast<CtaValue>,\n ) => Promise<CtaValue | null>"
3313
3334
  }
@@ -3326,7 +3347,7 @@
3326
3347
  },
3327
3348
  "location": {
3328
3349
  "filePath": "src/ctx/base.ts",
3329
- "lineNumber": 333
3350
+ "lineNumber": 518
3330
3351
  },
3331
3352
  "type": "(itemTypeId: string) => Promise<Item | null>"
3332
3353
  },
@@ -3337,7 +3358,7 @@
3337
3358
  },
3338
3359
  "location": {
3339
3360
  "filePath": "src/ctx/base.ts",
3340
- "lineNumber": 354
3361
+ "lineNumber": 539
3341
3362
  },
3342
3363
  "type": "{\n (\n itemTypeId: string,\n options: { multiple: true; initialLocationQuery?: ItemListLocationQuery },\n ): Promise<Item[] | null>;\n (\n itemTypeId: string,\n options?: {\n multiple: false;\n initialLocationQuery?: ItemListLocationQuery;\n },\n ): Promise<Item | null>;\n }"
3343
3364
  },
@@ -3348,7 +3369,7 @@
3348
3369
  },
3349
3370
  "location": {
3350
3371
  "filePath": "src/ctx/base.ts",
3351
- "lineNumber": 386
3372
+ "lineNumber": 571
3352
3373
  },
3353
3374
  "type": "(itemId: string) => Promise<Item | null>"
3354
3375
  }
@@ -3367,7 +3388,7 @@
3367
3388
  },
3368
3389
  "location": {
3369
3390
  "filePath": "src/ctx/base.ts",
3370
- "lineNumber": 474
3391
+ "lineNumber": 659
3371
3392
  },
3372
3393
  "type": "{\n (options: { multiple: true }): Promise<Upload[] | null>;\n (options?: { multiple: false }): Promise<Upload | null>;\n }"
3373
3394
  },
@@ -3378,7 +3399,7 @@
3378
3399
  },
3379
3400
  "location": {
3380
3401
  "filePath": "src/ctx/base.ts",
3381
- "lineNumber": 502
3402
+ "lineNumber": 687
3382
3403
  },
3383
3404
  "type": "(\n uploadId: string,\n ) => Promise<(Upload & { deleted?: true }) | null>"
3384
3405
  },
@@ -3389,7 +3410,7 @@
3389
3410
  },
3390
3411
  "location": {
3391
3412
  "filePath": "src/ctx/base.ts",
3392
- "lineNumber": 530
3413
+ "lineNumber": 715
3393
3414
  },
3394
3415
  "type": "(\n /** The \"single asset\" field structure */\n fileFieldValue: FileFieldValue,\n /** Shows metadata information for a specific locale */\n locale?: string,\n ) => Promise<FileFieldValue | null>"
3395
3416
  }
@@ -3408,7 +3429,7 @@
3408
3429
  },
3409
3430
  "location": {
3410
3431
  "filePath": "src/ctx/base.ts",
3411
- "lineNumber": 561
3432
+ "lineNumber": 746
3412
3433
  },
3413
3434
  "type": "(modal: Modal) => Promise<unknown>"
3414
3435
  },
@@ -3419,7 +3440,7 @@
3419
3440
  },
3420
3441
  "location": {
3421
3442
  "filePath": "src/ctx/base.ts",
3422
- "lineNumber": 598
3443
+ "lineNumber": 783
3423
3444
  },
3424
3445
  "type": "(options: ConfirmOptions) => Promise<unknown>"
3425
3446
  }
@@ -3438,7 +3459,7 @@
3438
3459
  },
3439
3460
  "location": {
3440
3461
  "filePath": "src/ctx/base.ts",
3441
- "lineNumber": 612
3462
+ "lineNumber": 797
3442
3463
  },
3443
3464
  "type": "(path: string) => Promise<void>"
3444
3465
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datocms-plugin-sdk",
3
- "version": "2.1.1",
3
+ "version": "3.0.1-alpha.0",
4
4
  "description": "DatoCMS Plugin SDK",
5
5
  "keywords": [
6
6
  "datocms",
@@ -46,5 +46,5 @@
46
46
  "glob": "^11.0.0",
47
47
  "typescript": "^5.6.2"
48
48
  },
49
- "gitHead": "a8fcf4b05fe22e331b2fd95303793088aa15fedf"
49
+ "gitHead": "52e7affbf92416cbc1cde78e016a62f3ff1a95cf"
50
50
  }
package/src/connect.ts CHANGED
@@ -136,6 +136,15 @@ export type FullConnectParameters = AssetSourcesHook &
136
136
  UploadSidebarsHook &
137
137
  ValidateManualFieldExtensionParametersHook;
138
138
 
139
+ function applyColorScheme(properties: unknown): void {
140
+ if (typeof document === 'undefined') return;
141
+ const next = (properties as { colorScheme?: 'light' | 'dark' } | null)
142
+ ?.colorScheme;
143
+ if (next !== 'light' && next !== 'dark') return;
144
+ if (document.documentElement.dataset.theme === next) return;
145
+ document.documentElement.dataset.theme = next;
146
+ }
147
+
139
148
  export async function connect(
140
149
  rawConfiguration: Partial<FullConnectParameters> = {},
141
150
  ): Promise<void> {
@@ -185,6 +194,7 @@ export async function connect(
185
194
  ),
186
195
  ),
187
196
  onChange(newSettings: unknown) {
197
+ applyColorScheme(newSettings);
188
198
  if (onChangeListener) {
189
199
  onChangeListener(newSettings);
190
200
  }
@@ -212,6 +222,7 @@ export async function connect(
212
222
 
213
223
  const methods = await penpalConnection.promise;
214
224
  const initialProperties = await methods.getSettings();
225
+ applyColorScheme(initialProperties);
215
226
 
216
227
  if (initialProperties.mode === 'onBoot') {
217
228
  let currentProperties = initialProperties;
package/src/ctx/base.ts CHANGED
@@ -83,8 +83,32 @@ type ProjectProperties = {
83
83
  locale: string;
84
84
  };
85
85
 
86
- /** An object containing the theme colors for the current DatoCMS project */
86
+ /**
87
+ * An object containing the theme colors for the current DatoCMS project
88
+ *
89
+ * @deprecated Use `semanticColorTokensTheme` instead. This property is kept
90
+ * for backward compatibility with third-party plugins.
91
+ */
87
92
  theme: Theme;
93
+
94
+ /**
95
+ * Semantic color tokens for the current DatoCMS project, pre-computed by
96
+ * the host. Only available on DatoCMS hosts that support the new token
97
+ * system.
98
+ */
99
+ semanticColorTokensTheme: SemanticColorTokensTheme;
100
+
101
+ /**
102
+ * The appearance color scheme the host CMS is currently using. Resolved —
103
+ * `'system'` is already expanded to `'light'` or `'dark'` by the host.
104
+ *
105
+ * The SDK runtime reflects this onto `document.documentElement` as
106
+ * `data-theme="light"` / `data-theme="dark"` so plugin CSS can branch
107
+ * with `[data-theme="dark"] { … }` selectors. For non-CSS decisions
108
+ * (choosing a logo asset, a syntax-highlighting preset, …) branch on
109
+ * `ctx.colorScheme` directly.
110
+ */
111
+ colorScheme: 'light' | 'dark';
88
112
  };
89
113
 
90
114
  /**
@@ -125,7 +149,12 @@ type EntityReposProperties = {
125
149
  ssoUsers: Partial<Record<string, SsoUser>>;
126
150
  };
127
151
 
128
- /** An object containing the theme colors for the current DatoCMS project */
152
+ /**
153
+ * An object containing the theme colors for the current DatoCMS project
154
+ *
155
+ * @deprecated Use `SemanticColorTokensTheme` instead. This type is kept for
156
+ * backward compatibility with third-party plugins.
157
+ */
129
158
  export type Theme = {
130
159
  primaryColor: string;
131
160
  accentColor: string;
@@ -134,6 +163,162 @@ export type Theme = {
134
163
  darkColor: string;
135
164
  };
136
165
 
166
+ /**
167
+ * Known semantic color tokens provided by the DatoCMS host.
168
+ * All properties are optional — the host may not send all of them.
169
+ *
170
+ * camelCase keys are converted to kebab-case CSS custom properties via
171
+ * `camelToDash`. For example, `colorRaisedSurface` becomes
172
+ * `--color-raised-surface`.
173
+ */
174
+ type KnownSemanticColorTokens = {
175
+ /* --- Standalone --- */
176
+ colorSurface?: string;
177
+ colorSurfaceHover?: string;
178
+ colorSurfaceMuted?: string;
179
+ colorInk?: string;
180
+ colorInkSubtle?: string;
181
+ colorInkHover?: string;
182
+ colorInkMuted?: string;
183
+ colorInkPlaceholder?: string;
184
+ colorInkPrimary?: string;
185
+ colorInkAccent?: string;
186
+ colorInkDisabled?: string;
187
+ colorBorder?: string;
188
+ colorBorderHover?: string;
189
+
190
+ /* --- Context: raised --- */
191
+ colorRaisedSurface?: string;
192
+ colorRaisedSurfaceHover?: string;
193
+ colorRaisedSurfaceActive?: string;
194
+
195
+ /* --- Context: primary --- */
196
+ colorPrimarySurface?: string;
197
+ colorPrimarySurfaceHover?: string;
198
+ colorPrimarySurfaceActive?: string;
199
+ colorPrimarySurfaceMuted?: string;
200
+ colorPrimaryInk?: string;
201
+ colorPrimaryBorder?: string;
202
+
203
+ /* --- Context: tinted --- */
204
+ colorTintedSurface?: string;
205
+ colorTintedSurfaceHover?: string;
206
+ colorTintedSurfaceActive?: string;
207
+ colorTintedInk?: string;
208
+
209
+ /* --- Context: accent --- */
210
+ colorAccentSurface?: string;
211
+ colorAccentInk?: string;
212
+
213
+ /* --- Context: selected --- */
214
+ colorSelectedSurface?: string;
215
+ colorSelectedInk?: string;
216
+ colorSelectedBorder?: string;
217
+
218
+ /* --- Context: disabled --- */
219
+ colorDisabledSurface?: string;
220
+ colorDisabledInk?: string;
221
+
222
+ /* --- Context: danger --- */
223
+ colorDangerSurface?: string;
224
+ colorDangerInk?: string;
225
+
226
+ /* --- Context: enterprise --- */
227
+ colorEnterpriseSurface?: string;
228
+
229
+ /* --- Context: focus --- */
230
+ colorFocusBorder?: string;
231
+ colorFocusOutline?: string;
232
+
233
+ /* --- Feedback --- */
234
+ colorFeedbackFailInk?: string;
235
+ colorFeedbackFailBorder?: string;
236
+ colorFeedbackFailOutline?: string;
237
+ colorFeedbackWarningInk?: string;
238
+ colorFeedbackWarningSurface?: string;
239
+ colorFeedbackSuccessInk?: string;
240
+ colorFeedbackWarningBorder?: string;
241
+ colorFeedbackSuccessBorder?: string;
242
+
243
+ /* --- Context: highlight --- */
244
+ colorHighlightSurface?: string;
245
+
246
+ /* --- Diffs --- */
247
+ colorDiffAddedSurface?: string;
248
+ colorDiffRemovedSurface?: string;
249
+ colorDiffChangedSurface?: string;
250
+ colorDiffAddedSurfaceSubtle?: string;
251
+ colorDiffRemovedSurfaceSubtle?: string;
252
+ colorDiffChangedSurfaceSubtle?: string;
253
+ colorDiffAddedOutlineSubtle?: string;
254
+ colorDiffRemovedOutlineSubtle?: string;
255
+ colorDiffChangedOutlineSubtle?: string;
256
+ colorDiffChangedBorder?: string;
257
+ colorDiffChangedBorderNegative?: string;
258
+
259
+ /* --- Status --- */
260
+ colorStatusDraftInk?: string;
261
+ colorStatusOutdatedInk?: string;
262
+ colorStatusPublishedInk?: string;
263
+
264
+ /* --- Backdrop --- */
265
+ colorBackdropSurface?: string;
266
+ colorBackdropInk?: string;
267
+
268
+ /* --- Overlay --- */
269
+ colorOverlaySurface?: string;
270
+ colorOverlaySurfaceSubtle?: string;
271
+ colorOverlayInk?: string;
272
+
273
+ /* --- Stacked --- */
274
+ colorStackedSurfaceBase?: string;
275
+ colorStackedSurface?: string;
276
+ colorStackedSurfaceRaised?: string;
277
+ colorStackedInk?: string;
278
+ colorStackedInkSubtle?: string;
279
+ colorStackedBorder?: string;
280
+ colorStackedSurfaceHover?: string;
281
+ colorStackedSurfaceTranslucent?: string;
282
+ colorStackedSurfaceButton?: string;
283
+ colorStackedSurfaceButtonActive?: string;
284
+
285
+ /* --- Progress --- */
286
+ colorProgressTrack?: string;
287
+ colorProgressFill?: string;
288
+ colorProgressFillHover?: string;
289
+
290
+ /* --- Tooltip --- */
291
+ colorTooltipSurface?: string;
292
+ colorTooltipSurfaceHover?: string;
293
+ colorTooltipInk?: string;
294
+ colorTooltipInkSubtle?: string;
295
+
296
+ /* --- Code --- */
297
+ colorCodeSurface?: string;
298
+ colorCodeInk?: string;
299
+
300
+ /* --- Shadows --- */
301
+ colorShadowSubtle?: string;
302
+ colorShadow?: string;
303
+ colorShadowStrong?: string;
304
+
305
+ /* --- Scrollbar --- */
306
+ colorScrollbar?: string;
307
+
308
+ /* --- Shadow composites --- */
309
+ shadowElevated?: string;
310
+ shadowFloat?: string;
311
+ shadowAmbient?: string;
312
+ };
313
+
314
+ /**
315
+ * Semantic color tokens for the current DatoCMS project, pre-computed by the
316
+ * host. Known tokens get autocomplete; unknown tokens are accepted via the
317
+ * index signature for forward compatibility.
318
+ */
319
+ export type SemanticColorTokensTheme = KnownSemanticColorTokens &
320
+ Record<string, string>;
321
+
137
322
  export type BaseMethods = LoadDataMethods &
138
323
  UpdatePluginParametersMethods &
139
324
  ToastMethods &