datocms-plugin-sdk 2.1.1 → 2.2.0-alpha.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datocms-plugin-sdk",
3
- "version": "2.1.1",
3
+ "version": "2.2.0-alpha.1",
4
4
  "description": "DatoCMS Plugin SDK",
5
5
  "keywords": [
6
6
  "datocms",
@@ -38,7 +38,7 @@
38
38
  "dependencies": {
39
39
  "@datocms/cma-client": "*",
40
40
  "@types/react": "^17.0.3",
41
- "datocms-structured-text-utils": "^2.0.0",
41
+ "datocms-structured-text-utils": "^5.1.16",
42
42
  "emoji-regex-xs": "*",
43
43
  "penpal": "^4.1.1"
44
44
  },
@@ -46,5 +46,5 @@
46
46
  "glob": "^11.0.0",
47
47
  "typescript": "^5.6.2"
48
48
  },
49
- "gitHead": "a8fcf4b05fe22e331b2fd95303793088aa15fedf"
49
+ "gitHead": "998ccd009a2babbc49d883ea4b0ef6539937271c"
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
@@ -63,6 +63,25 @@ type ProjectProperties = {
63
63
  /** Whether the current environment is the primary one */
64
64
  isEnvironmentPrimary: boolean;
65
65
 
66
+ /**
67
+ * The URL of the Content Delivery API (GraphQL) endpoint for the current
68
+ * project and environment.
69
+ *
70
+ * In the vast majority of cases you don't need this: the CDA endpoint is at a
71
+ * well-known, stable URL. It's exposed here only to support DatoCMS internal
72
+ * testing against non-production environments (e.g. staging).
73
+ */
74
+ cdaEndpointUrl: string;
75
+
76
+ /**
77
+ * The base URL of the Content Management API.
78
+ *
79
+ * In the vast majority of cases you don't need this: the CMA lives at a
80
+ * well-known, stable URL. It's exposed here only to support DatoCMS internal
81
+ * testing against non-production environments (e.g. staging).
82
+ */
83
+ cmaBaseUrl: string;
84
+
66
85
  /** The account/organization that is the project owner */
67
86
  owner: Account | Organization;
68
87
 
@@ -83,8 +102,33 @@ type ProjectProperties = {
83
102
  locale: string;
84
103
  };
85
104
 
86
- /** 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 `semanticColorTokensTheme` instead. This property is kept
109
+ * for backward compatibility with third-party plugins.
110
+ */
87
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
+ semanticColorTokensTheme: SemanticColorTokensTheme;
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` as
126
+ * `data-theme="light"` / `data-theme="dark"` so plugin CSS can branch
127
+ * with `[data-theme="dark"] { … }` selectors. For non-CSS decisions
128
+ * (choosing a logo asset, a syntax-highlighting preset, …) branch on
129
+ * `ctx.colorScheme` directly.
130
+ */
131
+ colorScheme: 'light' | 'dark';
88
132
  };
89
133
 
90
134
  /**
@@ -125,7 +169,12 @@ type EntityReposProperties = {
125
169
  ssoUsers: Partial<Record<string, SsoUser>>;
126
170
  };
127
171
 
128
- /** An object containing the theme colors for the current DatoCMS project */
172
+ /**
173
+ * An object containing the theme colors for the current DatoCMS project
174
+ *
175
+ * @deprecated Use `SemanticColorTokensTheme` instead. This type is kept for
176
+ * backward compatibility with third-party plugins.
177
+ */
129
178
  export type Theme = {
130
179
  primaryColor: string;
131
180
  accentColor: string;
@@ -134,6 +183,21 @@ export type Theme = {
134
183
  darkColor: string;
135
184
  };
136
185
 
186
+ /**
187
+ * Semantic color tokens for the current DatoCMS project, pre-computed by the
188
+ * host. Only available on DatoCMS hosts that support the new token system.
189
+ *
190
+ * Each key is a ready-to-use CSS custom property name (including the leading
191
+ * `--`), and each value is the resolved color for the host's current color
192
+ * scheme — e.g. `{ '--color--raised--surface': 'oklch(…)' }`. The SDK applies
193
+ * these verbatim onto the plugin canvas, so plugin CSS can reference them
194
+ * directly with `var(--color--raised--surface)`.
195
+ *
196
+ * The token set is whatever the host sends; it is intentionally untyped so it
197
+ * can evolve on the host without an SDK release.
198
+ */
199
+ export type SemanticColorTokensTheme = Record<string, string>;
200
+
137
201
  export type BaseMethods = LoadDataMethods &
138
202
  UpdatePluginParametersMethods &
139
203
  ToastMethods &
package/src/manifest.ts CHANGED
@@ -3302,6 +3302,28 @@ export const manifest: Manifest = {
3302
3302
  },
3303
3303
  type: 'boolean',
3304
3304
  },
3305
+ cdaEndpointUrl: {
3306
+ comment: {
3307
+ markdownText:
3308
+ "The URL of the Content Delivery API (GraphQL) endpoint for the current\nproject and environment.\n\nIn the vast majority of cases you don't need this: the CDA endpoint is at a\nwell-known, stable URL. It's exposed here only to support DatoCMS internal\ntesting against non-production environments (e.g. staging).",
3309
+ },
3310
+ location: {
3311
+ filePath: 'src/ctx/base.ts',
3312
+ lineNumber: 74,
3313
+ },
3314
+ type: 'string',
3315
+ },
3316
+ cmaBaseUrl: {
3317
+ comment: {
3318
+ markdownText:
3319
+ "The base URL of the Content Management API.\n\nIn the vast majority of cases you don't need this: the CMA lives at a\nwell-known, stable URL. It's exposed here only to support DatoCMS internal\ntesting against non-production environments (e.g. staging).",
3320
+ },
3321
+ location: {
3322
+ filePath: 'src/ctx/base.ts',
3323
+ lineNumber: 83,
3324
+ },
3325
+ type: 'string',
3326
+ },
3305
3327
  owner: {
3306
3328
  comment: {
3307
3329
  markdownText:
@@ -3309,7 +3331,7 @@ export const manifest: Manifest = {
3309
3331
  },
3310
3332
  location: {
3311
3333
  filePath: 'src/ctx/base.ts',
3312
- lineNumber: 67,
3334
+ lineNumber: 86,
3313
3335
  },
3314
3336
  type: 'Account | Organization',
3315
3337
  },
@@ -3321,7 +3343,7 @@ export const manifest: Manifest = {
3321
3343
  },
3322
3344
  location: {
3323
3345
  filePath: 'src/ctx/base.ts',
3324
- lineNumber: 75,
3346
+ lineNumber: 94,
3325
3347
  },
3326
3348
  type: 'Account | undefined',
3327
3349
  },
@@ -3332,7 +3354,7 @@ export const manifest: Manifest = {
3332
3354
  },
3333
3355
  location: {
3334
3356
  filePath: 'src/ctx/base.ts',
3335
- lineNumber: 81,
3357
+ lineNumber: 100,
3336
3358
  },
3337
3359
  type: '{\n /** Preferred locale */\n locale: string;\n }',
3338
3360
  },
@@ -3340,13 +3362,37 @@ export const manifest: Manifest = {
3340
3362
  comment: {
3341
3363
  markdownText:
3342
3364
  'An object containing the theme colors for the current DatoCMS project.',
3365
+ deprecatedMarkdownText:
3366
+ 'Use `semanticColorTokensTheme` instead. This property is kept\nfor backward compatibility with third-party plugins.',
3343
3367
  },
3344
3368
  location: {
3345
3369
  filePath: 'src/ctx/base.ts',
3346
- lineNumber: 87,
3370
+ lineNumber: 111,
3347
3371
  },
3348
3372
  type: 'Theme',
3349
3373
  },
3374
+ semanticColorTokensTheme: {
3375
+ comment: {
3376
+ markdownText:
3377
+ '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.',
3378
+ },
3379
+ location: {
3380
+ filePath: 'src/ctx/base.ts',
3381
+ lineNumber: 119,
3382
+ },
3383
+ type: 'SemanticColorTokensTheme',
3384
+ },
3385
+ colorScheme: {
3386
+ comment: {
3387
+ markdownText:
3388
+ '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.',
3389
+ },
3390
+ location: {
3391
+ filePath: 'src/ctx/base.ts',
3392
+ lineNumber: 131,
3393
+ },
3394
+ type: "'light' | 'dark'",
3395
+ },
3350
3396
  },
3351
3397
  },
3352
3398
  {
@@ -3363,7 +3409,7 @@ export const manifest: Manifest = {
3363
3409
  },
3364
3410
  location: {
3365
3411
  filePath: 'src/ctx/base.ts',
3366
- lineNumber: 97,
3412
+ lineNumber: 141,
3367
3413
  },
3368
3414
  type: 'Partial<Record<string, ItemType>>',
3369
3415
  },
@@ -3374,7 +3420,7 @@ export const manifest: Manifest = {
3374
3420
  },
3375
3421
  location: {
3376
3422
  filePath: 'src/ctx/base.ts',
3377
- lineNumber: 104,
3423
+ lineNumber: 148,
3378
3424
  },
3379
3425
  type: 'Partial<Record<string, Field>>',
3380
3426
  },
@@ -3385,7 +3431,7 @@ export const manifest: Manifest = {
3385
3431
  },
3386
3432
  location: {
3387
3433
  filePath: 'src/ctx/base.ts',
3388
- lineNumber: 111,
3434
+ lineNumber: 155,
3389
3435
  },
3390
3436
  type: 'Partial<Record<string, Fieldset>>',
3391
3437
  },
@@ -3396,7 +3442,7 @@ export const manifest: Manifest = {
3396
3442
  },
3397
3443
  location: {
3398
3444
  filePath: 'src/ctx/base.ts',
3399
- lineNumber: 118,
3445
+ lineNumber: 162,
3400
3446
  },
3401
3447
  type: 'Partial<Record<string, User>>',
3402
3448
  },
@@ -3407,7 +3453,7 @@ export const manifest: Manifest = {
3407
3453
  },
3408
3454
  location: {
3409
3455
  filePath: 'src/ctx/base.ts',
3410
- lineNumber: 125,
3456
+ lineNumber: 169,
3411
3457
  },
3412
3458
  type: 'Partial<Record<string, SsoUser>>',
3413
3459
  },
@@ -3431,7 +3477,7 @@ export const manifest: Manifest = {
3431
3477
  },
3432
3478
  location: {
3433
3479
  filePath: 'src/ctx/base.ts',
3434
- lineNumber: 168,
3480
+ lineNumber: 232,
3435
3481
  },
3436
3482
  type: '(itemTypeId: string) => Promise<Field[]>',
3437
3483
  },
@@ -3444,7 +3490,7 @@ export const manifest: Manifest = {
3444
3490
  },
3445
3491
  location: {
3446
3492
  filePath: 'src/ctx/base.ts',
3447
- lineNumber: 187,
3493
+ lineNumber: 251,
3448
3494
  },
3449
3495
  type: '(itemTypeId: string) => Promise<Fieldset[]>',
3450
3496
  },
@@ -3457,7 +3503,7 @@ export const manifest: Manifest = {
3457
3503
  },
3458
3504
  location: {
3459
3505
  filePath: 'src/ctx/base.ts',
3460
- lineNumber: 204,
3506
+ lineNumber: 268,
3461
3507
  },
3462
3508
  type: '() => Promise<Field[]>',
3463
3509
  },
@@ -3470,7 +3516,7 @@ export const manifest: Manifest = {
3470
3516
  },
3471
3517
  location: {
3472
3518
  filePath: 'src/ctx/base.ts',
3473
- lineNumber: 217,
3519
+ lineNumber: 281,
3474
3520
  },
3475
3521
  type: '() => Promise<User[]>',
3476
3522
  },
@@ -3483,7 +3529,7 @@ export const manifest: Manifest = {
3483
3529
  },
3484
3530
  location: {
3485
3531
  filePath: 'src/ctx/base.ts',
3486
- lineNumber: 230,
3532
+ lineNumber: 294,
3487
3533
  },
3488
3534
  type: '() => Promise<SsoUser[]>',
3489
3535
  },
@@ -3505,7 +3551,7 @@ export const manifest: Manifest = {
3505
3551
  },
3506
3552
  location: {
3507
3553
  filePath: 'src/ctx/base.ts',
3508
- lineNumber: 252,
3554
+ lineNumber: 316,
3509
3555
  },
3510
3556
  type: '(params: Record<string, unknown>) => Promise<void>',
3511
3557
  },
@@ -3518,7 +3564,7 @@ export const manifest: Manifest = {
3518
3564
  },
3519
3565
  location: {
3520
3566
  filePath: 'src/ctx/base.ts',
3521
- lineNumber: 303,
3567
+ lineNumber: 367,
3522
3568
  },
3523
3569
  type: '(\n fieldId: string,\n changes: FieldAppearanceChange[],\n ) => Promise<void>',
3524
3570
  },
@@ -3540,7 +3586,7 @@ export const manifest: Manifest = {
3540
3586
  },
3541
3587
  location: {
3542
3588
  filePath: 'src/ctx/base.ts',
3543
- lineNumber: 408,
3589
+ lineNumber: 472,
3544
3590
  },
3545
3591
  type: '(message: string) => Promise<void>',
3546
3592
  },
@@ -3553,7 +3599,7 @@ export const manifest: Manifest = {
3553
3599
  },
3554
3600
  location: {
3555
3601
  filePath: 'src/ctx/base.ts',
3556
- lineNumber: 423,
3602
+ lineNumber: 487,
3557
3603
  },
3558
3604
  type: '(message: string) => Promise<void>',
3559
3605
  },
@@ -3566,7 +3612,7 @@ export const manifest: Manifest = {
3566
3612
  },
3567
3613
  location: {
3568
3614
  filePath: 'src/ctx/base.ts',
3569
- lineNumber: 447,
3615
+ lineNumber: 511,
3570
3616
  },
3571
3617
  type: '<CtaValue = unknown>(\n toast: Toast<CtaValue>,\n ) => Promise<CtaValue | null>',
3572
3618
  },
@@ -3588,7 +3634,7 @@ export const manifest: Manifest = {
3588
3634
  },
3589
3635
  location: {
3590
3636
  filePath: 'src/ctx/base.ts',
3591
- lineNumber: 333,
3637
+ lineNumber: 397,
3592
3638
  },
3593
3639
  type: '(itemTypeId: string) => Promise<Item | null>',
3594
3640
  },
@@ -3601,7 +3647,7 @@ export const manifest: Manifest = {
3601
3647
  },
3602
3648
  location: {
3603
3649
  filePath: 'src/ctx/base.ts',
3604
- lineNumber: 354,
3650
+ lineNumber: 418,
3605
3651
  },
3606
3652
  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 }',
3607
3653
  },
@@ -3614,7 +3660,7 @@ export const manifest: Manifest = {
3614
3660
  },
3615
3661
  location: {
3616
3662
  filePath: 'src/ctx/base.ts',
3617
- lineNumber: 386,
3663
+ lineNumber: 450,
3618
3664
  },
3619
3665
  type: '(itemId: string) => Promise<Item | null>',
3620
3666
  },
@@ -3636,7 +3682,7 @@ export const manifest: Manifest = {
3636
3682
  },
3637
3683
  location: {
3638
3684
  filePath: 'src/ctx/base.ts',
3639
- lineNumber: 474,
3685
+ lineNumber: 538,
3640
3686
  },
3641
3687
  type: '{\n (options: { multiple: true }): Promise<Upload[] | null>;\n (options?: { multiple: false }): Promise<Upload | null>;\n }',
3642
3688
  },
@@ -3649,7 +3695,7 @@ export const manifest: Manifest = {
3649
3695
  },
3650
3696
  location: {
3651
3697
  filePath: 'src/ctx/base.ts',
3652
- lineNumber: 502,
3698
+ lineNumber: 566,
3653
3699
  },
3654
3700
  type: '(\n uploadId: string,\n ) => Promise<(Upload & { deleted?: true }) | null>',
3655
3701
  },
@@ -3662,7 +3708,7 @@ export const manifest: Manifest = {
3662
3708
  },
3663
3709
  location: {
3664
3710
  filePath: 'src/ctx/base.ts',
3665
- lineNumber: 530,
3711
+ lineNumber: 594,
3666
3712
  },
3667
3713
  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>',
3668
3714
  },
@@ -3684,7 +3730,7 @@ export const manifest: Manifest = {
3684
3730
  },
3685
3731
  location: {
3686
3732
  filePath: 'src/ctx/base.ts',
3687
- lineNumber: 561,
3733
+ lineNumber: 625,
3688
3734
  },
3689
3735
  type: '(modal: Modal) => Promise<unknown>',
3690
3736
  },
@@ -3697,7 +3743,7 @@ export const manifest: Manifest = {
3697
3743
  },
3698
3744
  location: {
3699
3745
  filePath: 'src/ctx/base.ts',
3700
- lineNumber: 598,
3746
+ lineNumber: 662,
3701
3747
  },
3702
3748
  type: '(options: ConfirmOptions) => Promise<unknown>',
3703
3749
  },
@@ -3718,7 +3764,7 @@ export const manifest: Manifest = {
3718
3764
  },
3719
3765
  location: {
3720
3766
  filePath: 'src/ctx/base.ts',
3721
- lineNumber: 612,
3767
+ lineNumber: 676,
3722
3768
  },
3723
3769
  type: '(path: string) => Promise<void>',
3724
3770
  },