datocms-plugin-sdk 2.1.5 → 2.2.0-alpha.2

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.
@@ -79,8 +79,34 @@ type ProjectProperties = {
79
79
  /** Preferred locale */
80
80
  locale: string;
81
81
  };
82
- /** An object containing the theme colors for the current DatoCMS project */
82
+ /**
83
+ * An object containing the theme colors for the current DatoCMS project
84
+ *
85
+ * @deprecated Use `cssDesignTokens` instead. This property is kept
86
+ * for backward compatibility with third-party plugins.
87
+ */
83
88
  theme: Theme;
89
+ /**
90
+ * Semantic color tokens for the current DatoCMS project, pre-computed by
91
+ * the host. A map of CSS custom property names (e.g.
92
+ * `--color--raised--surface`) to their resolved values for the current
93
+ * color scheme.
94
+ */
95
+ cssDesignTokens: cssDesignTokens;
96
+ /**
97
+ * The appearance color scheme the host CMS is currently using. Resolved —
98
+ * `'system'` is already expanded to `'light'` or `'dark'` by the host.
99
+ *
100
+ * The SDK runtime reflects this onto `document.documentElement` two ways:
101
+ * the `data-color-scheme="light"` / `data-color-scheme="dark"` attribute,
102
+ * so plugin CSS can branch with `[data-color-scheme="dark"] { … }`
103
+ * selectors; and the actual `color-scheme` CSS property, so `light-dark()`
104
+ * resolves to the correct branch (and native form controls / scrollbars
105
+ * match) everywhere in the plugin frame. For non-CSS decisions (choosing a
106
+ * logo asset, a syntax-highlighting preset, …) branch on `ctx.colorScheme`
107
+ * directly.
108
+ */
109
+ colorScheme: 'light' | 'dark';
84
110
  };
85
111
  /**
86
112
  * These properties provide access to "entity repos", that is, the collection of
@@ -115,7 +141,12 @@ type EntityReposProperties = {
115
141
  */
116
142
  ssoUsers: Partial<Record<string, SsoUser>>;
117
143
  };
118
- /** An object containing the theme colors for the current DatoCMS project */
144
+ /**
145
+ * An object containing the theme colors for the current DatoCMS project
146
+ *
147
+ * @deprecated Use `cssDesignTokens` instead. This type is kept for
148
+ * backward compatibility with third-party plugins.
149
+ */
119
150
  export type Theme = {
120
151
  primaryColor: string;
121
152
  accentColor: string;
@@ -123,6 +154,20 @@ export type Theme = {
123
154
  lightColor: string;
124
155
  darkColor: string;
125
156
  };
157
+ /**
158
+ * Semantic color tokens for the current DatoCMS project, pre-computed by the
159
+ * host. Only available on DatoCMS hosts that support the new token system.
160
+ *
161
+ * Each key is a ready-to-use CSS custom property name (including the leading
162
+ * `--`), and each value is the resolved color for the host's current color
163
+ * scheme — e.g. `{ '--color--raised--surface': 'oklch(…)' }`. The SDK applies
164
+ * these verbatim onto the plugin canvas, so plugin CSS can reference them
165
+ * directly with `var(--color--raised--surface)`.
166
+ *
167
+ * The token set is whatever the host sends; it is intentionally untyped so it
168
+ * can evolve on the host without an SDK release.
169
+ */
170
+ export type cssDesignTokens = Record<string, string>;
126
171
  export type BaseMethods = LoadDataMethods & UpdatePluginParametersMethods & ToastMethods & ItemDialogMethods & UploadDialogMethods & CustomDialogMethods & NavigateMethods;
127
172
  /**
128
173
  * These methods can be used to asyncronously load additional information your
package/manifest.json CHANGED
@@ -3129,13 +3129,34 @@
3129
3129
  },
3130
3130
  "theme": {
3131
3131
  "comment": {
3132
- "markdownText": "An object containing the theme colors for the current DatoCMS project."
3132
+ "markdownText": "An object containing the theme colors for the current DatoCMS project.",
3133
+ "deprecatedMarkdownText": "Use `cssDesignTokens` instead. This property is kept\nfor backward compatibility with third-party plugins."
3133
3134
  },
3134
3135
  "location": {
3135
3136
  "filePath": "src/ctx/base.ts",
3136
- "lineNumber": 106
3137
+ "lineNumber": 111
3137
3138
  },
3138
3139
  "type": "Theme"
3140
+ },
3141
+ "cssDesignTokens": {
3142
+ "comment": {
3143
+ "markdownText": "Semantic color tokens for the current DatoCMS project, pre-computed by\nthe host. A map of CSS custom property names (e.g.\n`--color--raised--surface`) to their resolved values for the current\ncolor scheme."
3144
+ },
3145
+ "location": {
3146
+ "filePath": "src/ctx/base.ts",
3147
+ "lineNumber": 119
3148
+ },
3149
+ "type": "cssDesignTokens"
3150
+ },
3151
+ "colorScheme": {
3152
+ "comment": {
3153
+ "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` two ways:\nthe `data-color-scheme=\"light\"` / `data-color-scheme=\"dark\"` attribute,\nso plugin CSS can branch with `[data-color-scheme=\"dark\"] { … }`\nselectors; and the actual `color-scheme` CSS property, so `light-dark()`\nresolves to the correct branch (and native form controls / scrollbars\nmatch) everywhere in the plugin frame. For non-CSS decisions (choosing a\nlogo asset, a syntax-highlighting preset, …) branch on `ctx.colorScheme`\ndirectly."
3154
+ },
3155
+ "location": {
3156
+ "filePath": "src/ctx/base.ts",
3157
+ "lineNumber": 134
3158
+ },
3159
+ "type": "'light' | 'dark'"
3139
3160
  }
3140
3161
  }
3141
3162
  },
@@ -3151,7 +3172,7 @@
3151
3172
  },
3152
3173
  "location": {
3153
3174
  "filePath": "src/ctx/base.ts",
3154
- "lineNumber": 116
3175
+ "lineNumber": 144
3155
3176
  },
3156
3177
  "type": "Partial<Record<string, ItemType>>"
3157
3178
  },
@@ -3161,7 +3182,7 @@
3161
3182
  },
3162
3183
  "location": {
3163
3184
  "filePath": "src/ctx/base.ts",
3164
- "lineNumber": 123
3185
+ "lineNumber": 151
3165
3186
  },
3166
3187
  "type": "Partial<Record<string, Field>>"
3167
3188
  },
@@ -3171,7 +3192,7 @@
3171
3192
  },
3172
3193
  "location": {
3173
3194
  "filePath": "src/ctx/base.ts",
3174
- "lineNumber": 130
3195
+ "lineNumber": 158
3175
3196
  },
3176
3197
  "type": "Partial<Record<string, Fieldset>>"
3177
3198
  },
@@ -3181,7 +3202,7 @@
3181
3202
  },
3182
3203
  "location": {
3183
3204
  "filePath": "src/ctx/base.ts",
3184
- "lineNumber": 137
3205
+ "lineNumber": 165
3185
3206
  },
3186
3207
  "type": "Partial<Record<string, User>>"
3187
3208
  },
@@ -3191,7 +3212,7 @@
3191
3212
  },
3192
3213
  "location": {
3193
3214
  "filePath": "src/ctx/base.ts",
3194
- "lineNumber": 144
3215
+ "lineNumber": 172
3195
3216
  },
3196
3217
  "type": "Partial<Record<string, SsoUser>>"
3197
3218
  }
@@ -3212,7 +3233,7 @@
3212
3233
  },
3213
3234
  "location": {
3214
3235
  "filePath": "src/ctx/base.ts",
3215
- "lineNumber": 187
3236
+ "lineNumber": 235
3216
3237
  },
3217
3238
  "type": "(itemTypeId: string) => Promise<Field[]>"
3218
3239
  },
@@ -3223,7 +3244,7 @@
3223
3244
  },
3224
3245
  "location": {
3225
3246
  "filePath": "src/ctx/base.ts",
3226
- "lineNumber": 206
3247
+ "lineNumber": 254
3227
3248
  },
3228
3249
  "type": "(itemTypeId: string) => Promise<Fieldset[]>"
3229
3250
  },
@@ -3234,7 +3255,7 @@
3234
3255
  },
3235
3256
  "location": {
3236
3257
  "filePath": "src/ctx/base.ts",
3237
- "lineNumber": 223
3258
+ "lineNumber": 271
3238
3259
  },
3239
3260
  "type": "() => Promise<Field[]>"
3240
3261
  },
@@ -3245,7 +3266,7 @@
3245
3266
  },
3246
3267
  "location": {
3247
3268
  "filePath": "src/ctx/base.ts",
3248
- "lineNumber": 236
3269
+ "lineNumber": 284
3249
3270
  },
3250
3271
  "type": "() => Promise<User[]>"
3251
3272
  },
@@ -3256,7 +3277,7 @@
3256
3277
  },
3257
3278
  "location": {
3258
3279
  "filePath": "src/ctx/base.ts",
3259
- "lineNumber": 249
3280
+ "lineNumber": 297
3260
3281
  },
3261
3282
  "type": "() => Promise<SsoUser[]>"
3262
3283
  }
@@ -3275,7 +3296,7 @@
3275
3296
  },
3276
3297
  "location": {
3277
3298
  "filePath": "src/ctx/base.ts",
3278
- "lineNumber": 271
3299
+ "lineNumber": 319
3279
3300
  },
3280
3301
  "type": "(params: Record<string, unknown>) => Promise<void>"
3281
3302
  },
@@ -3286,7 +3307,7 @@
3286
3307
  },
3287
3308
  "location": {
3288
3309
  "filePath": "src/ctx/base.ts",
3289
- "lineNumber": 322
3310
+ "lineNumber": 370
3290
3311
  },
3291
3312
  "type": "(\n fieldId: string,\n changes: FieldAppearanceChange[],\n ) => Promise<void>"
3292
3313
  }
@@ -3305,7 +3326,7 @@
3305
3326
  },
3306
3327
  "location": {
3307
3328
  "filePath": "src/ctx/base.ts",
3308
- "lineNumber": 427
3329
+ "lineNumber": 475
3309
3330
  },
3310
3331
  "type": "(message: string) => Promise<void>"
3311
3332
  },
@@ -3316,7 +3337,7 @@
3316
3337
  },
3317
3338
  "location": {
3318
3339
  "filePath": "src/ctx/base.ts",
3319
- "lineNumber": 442
3340
+ "lineNumber": 490
3320
3341
  },
3321
3342
  "type": "(message: string) => Promise<void>"
3322
3343
  },
@@ -3327,7 +3348,7 @@
3327
3348
  },
3328
3349
  "location": {
3329
3350
  "filePath": "src/ctx/base.ts",
3330
- "lineNumber": 466
3351
+ "lineNumber": 514
3331
3352
  },
3332
3353
  "type": "<CtaValue = unknown>(\n toast: Toast<CtaValue>,\n ) => Promise<CtaValue | null>"
3333
3354
  }
@@ -3346,7 +3367,7 @@
3346
3367
  },
3347
3368
  "location": {
3348
3369
  "filePath": "src/ctx/base.ts",
3349
- "lineNumber": 352
3370
+ "lineNumber": 400
3350
3371
  },
3351
3372
  "type": "(itemTypeId: string) => Promise<Item | null>"
3352
3373
  },
@@ -3357,7 +3378,7 @@
3357
3378
  },
3358
3379
  "location": {
3359
3380
  "filePath": "src/ctx/base.ts",
3360
- "lineNumber": 373
3381
+ "lineNumber": 421
3361
3382
  },
3362
3383
  "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 }"
3363
3384
  },
@@ -3368,7 +3389,7 @@
3368
3389
  },
3369
3390
  "location": {
3370
3391
  "filePath": "src/ctx/base.ts",
3371
- "lineNumber": 405
3392
+ "lineNumber": 453
3372
3393
  },
3373
3394
  "type": "(itemId: string) => Promise<Item | null>"
3374
3395
  }
@@ -3387,7 +3408,7 @@
3387
3408
  },
3388
3409
  "location": {
3389
3410
  "filePath": "src/ctx/base.ts",
3390
- "lineNumber": 493
3411
+ "lineNumber": 541
3391
3412
  },
3392
3413
  "type": "{\n (options: { multiple: true }): Promise<Upload[] | null>;\n (options?: { multiple: false }): Promise<Upload | null>;\n }"
3393
3414
  },
@@ -3398,7 +3419,7 @@
3398
3419
  },
3399
3420
  "location": {
3400
3421
  "filePath": "src/ctx/base.ts",
3401
- "lineNumber": 521
3422
+ "lineNumber": 569
3402
3423
  },
3403
3424
  "type": "(\n uploadId: string,\n ) => Promise<(Upload & { deleted?: true }) | null>"
3404
3425
  },
@@ -3409,7 +3430,7 @@
3409
3430
  },
3410
3431
  "location": {
3411
3432
  "filePath": "src/ctx/base.ts",
3412
- "lineNumber": 549
3433
+ "lineNumber": 597
3413
3434
  },
3414
3435
  "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>"
3415
3436
  }
@@ -3428,7 +3449,7 @@
3428
3449
  },
3429
3450
  "location": {
3430
3451
  "filePath": "src/ctx/base.ts",
3431
- "lineNumber": 580
3452
+ "lineNumber": 628
3432
3453
  },
3433
3454
  "type": "(modal: Modal) => Promise<unknown>"
3434
3455
  },
@@ -3439,7 +3460,7 @@
3439
3460
  },
3440
3461
  "location": {
3441
3462
  "filePath": "src/ctx/base.ts",
3442
- "lineNumber": 617
3463
+ "lineNumber": 665
3443
3464
  },
3444
3465
  "type": "(options: ConfirmOptions) => Promise<unknown>"
3445
3466
  }
@@ -3458,7 +3479,7 @@
3458
3479
  },
3459
3480
  "location": {
3460
3481
  "filePath": "src/ctx/base.ts",
3461
- "lineNumber": 631
3482
+ "lineNumber": 679
3462
3483
  },
3463
3484
  "type": "(path: string) => Promise<void>"
3464
3485
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datocms-plugin-sdk",
3
- "version": "2.1.5",
3
+ "version": "2.2.0-alpha.2",
4
4
  "description": "DatoCMS Plugin SDK",
5
5
  "keywords": [
6
6
  "datocms",
@@ -30,7 +30,8 @@
30
30
  "scripts": {
31
31
  "build": "npm run generate-manifest && tsc && tsc --project ./tsconfig.esnext.json",
32
32
  "generate-manifest": "tsx generateManifest.ts && biome format --write src/manifest.ts",
33
- "prebuild": "rimraf dist"
33
+ "prebuild": "rimraf dist",
34
+ "install-in-place": "npm run build && rm -rf $INSTALL_PATH/node_modules/datocms-plugin-sdk/dist && cp -rf dist manifest.json $INSTALL_PATH/node_modules/datocms-plugin-sdk"
34
35
  },
35
36
  "bugs": {
36
37
  "url": "https://github.com/datocms/plugins-sdk/issues"
@@ -46,5 +47,5 @@
46
47
  "glob": "^11.0.0",
47
48
  "typescript": "^5.6.2"
48
49
  },
49
- "gitHead": "1fc2f5b9c06a8bac49bd0e2cf731e599415ce010"
50
+ "gitHead": "2db7d26fc8a8c765621f30b2e1363af6036778c0"
50
51
  }
package/src/connect.ts CHANGED
@@ -136,6 +136,21 @@ 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.colorScheme === next) return;
145
+ document.documentElement.dataset.colorScheme = next;
146
+ // Also set the actual `color-scheme` CSS property on the root so that
147
+ // `light-dark()` resolves to the correct branch and native form controls /
148
+ // scrollbars match — everywhere in the plugin frame, including DOM rendered
149
+ // outside any `Canvas`/portal. The `data-color-scheme` attribute above is
150
+ // just a hook for explicit CSS branching; it doesn't drive `light-dark()`.
151
+ document.documentElement.style.colorScheme = next;
152
+ }
153
+
139
154
  export async function connect(
140
155
  rawConfiguration: Partial<FullConnectParameters> = {},
141
156
  ): Promise<void> {
@@ -167,7 +182,7 @@ export async function connect(
167
182
 
168
183
  const penpalConnection = connectToParent({
169
184
  methods: {
170
- sdkVersion: () => '0.3.0',
185
+ sdkVersion: () => '0.3.1',
171
186
  implementedHooks: () =>
172
187
  Object.fromEntries(
173
188
  Object.keys(rawConfiguration).map((hook) => {
@@ -185,6 +200,7 @@ export async function connect(
185
200
  ),
186
201
  ),
187
202
  onChange(newSettings: unknown) {
203
+ applyColorScheme(newSettings);
188
204
  if (onChangeListener) {
189
205
  onChangeListener(newSettings);
190
206
  }
@@ -212,6 +228,7 @@ export async function connect(
212
228
 
213
229
  const methods = await penpalConnection.promise;
214
230
  const initialProperties = await methods.getSettings();
231
+ applyColorScheme(initialProperties);
215
232
 
216
233
  if (initialProperties.mode === 'onBoot') {
217
234
  let currentProperties = initialProperties;
package/src/ctx/base.ts CHANGED
@@ -102,8 +102,36 @@ type ProjectProperties = {
102
102
  locale: string;
103
103
  };
104
104
 
105
- /** An object containing the theme colors for the current DatoCMS project */
105
+ /**
106
+ * An object containing the theme colors for the current DatoCMS project
107
+ *
108
+ * @deprecated Use `cssDesignTokens` instead. This property is kept
109
+ * for backward compatibility with third-party plugins.
110
+ */
106
111
  theme: Theme;
112
+
113
+ /**
114
+ * Semantic color tokens for the current DatoCMS project, pre-computed by
115
+ * the host. A map of CSS custom property names (e.g.
116
+ * `--color--raised--surface`) to their resolved values for the current
117
+ * color scheme.
118
+ */
119
+ cssDesignTokens: cssDesignTokens;
120
+
121
+ /**
122
+ * The appearance color scheme the host CMS is currently using. Resolved —
123
+ * `'system'` is already expanded to `'light'` or `'dark'` by the host.
124
+ *
125
+ * The SDK runtime reflects this onto `document.documentElement` two ways:
126
+ * the `data-color-scheme="light"` / `data-color-scheme="dark"` attribute,
127
+ * so plugin CSS can branch with `[data-color-scheme="dark"] { … }`
128
+ * selectors; and the actual `color-scheme` CSS property, so `light-dark()`
129
+ * resolves to the correct branch (and native form controls / scrollbars
130
+ * match) everywhere in the plugin frame. For non-CSS decisions (choosing a
131
+ * logo asset, a syntax-highlighting preset, …) branch on `ctx.colorScheme`
132
+ * directly.
133
+ */
134
+ colorScheme: 'light' | 'dark';
107
135
  };
108
136
 
109
137
  /**
@@ -144,7 +172,12 @@ type EntityReposProperties = {
144
172
  ssoUsers: Partial<Record<string, SsoUser>>;
145
173
  };
146
174
 
147
- /** An object containing the theme colors for the current DatoCMS project */
175
+ /**
176
+ * An object containing the theme colors for the current DatoCMS project
177
+ *
178
+ * @deprecated Use `cssDesignTokens` instead. This type is kept for
179
+ * backward compatibility with third-party plugins.
180
+ */
148
181
  export type Theme = {
149
182
  primaryColor: string;
150
183
  accentColor: string;
@@ -153,6 +186,21 @@ export type Theme = {
153
186
  darkColor: string;
154
187
  };
155
188
 
189
+ /**
190
+ * Semantic color tokens for the current DatoCMS project, pre-computed by the
191
+ * host. Only available on DatoCMS hosts that support the new token system.
192
+ *
193
+ * Each key is a ready-to-use CSS custom property name (including the leading
194
+ * `--`), and each value is the resolved color for the host's current color
195
+ * scheme — e.g. `{ '--color--raised--surface': 'oklch(…)' }`. The SDK applies
196
+ * these verbatim onto the plugin canvas, so plugin CSS can reference them
197
+ * directly with `var(--color--raised--surface)`.
198
+ *
199
+ * The token set is whatever the host sends; it is intentionally untyped so it
200
+ * can evolve on the host without an SDK release.
201
+ */
202
+ export type cssDesignTokens = Record<string, string>;
203
+
156
204
  export type BaseMethods = LoadDataMethods &
157
205
  UpdatePluginParametersMethods &
158
206
  ToastMethods &