datocms-plugin-sdk 0.8.2 → 1.0.0-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/src/connect.ts CHANGED
@@ -1,14 +1,17 @@
1
1
  import connectToParent from 'penpal/lib/connectToParent';
2
- import { SchemaTypes } from '@datocms/cma-client';
2
+ import {
3
+ Field,
4
+ Item,
5
+ ItemCreateSchema,
6
+ ItemType,
7
+ ItemUpdateSchema,
8
+ } from './SiteApiSchema';
3
9
  import {
4
10
  AssetSource,
5
11
  ContentAreaSidebarItem,
6
12
  FieldExtensionOverride,
7
- InitialLocationQueryForItemSelector,
8
13
  InitPropertiesAndMethods,
9
- ItemFormSidebar,
10
14
  ItemFormSidebarPanel,
11
- ItemPresentationInfo,
12
15
  MainNavigationTab,
13
16
  ManualFieldExtension,
14
17
  OnBootMethods,
@@ -27,8 +30,6 @@ import {
27
30
  RenderPagePropertiesAndMethods,
28
31
  RenderSidebarPanelMethods,
29
32
  RenderSidebarPanelPropertiesAndMethods,
30
- RenderSidebarPropertiesAndMethods,
31
- RenderSidebarMethods,
32
33
  SettingsAreaSidebarItemGroup,
33
34
  } from './types';
34
35
  import {
@@ -41,7 +42,6 @@ import {
41
42
  isRenderModalParent,
42
43
  isRenderPageParent,
43
44
  isRenderSidebarPanelParent,
44
- isRenderSidebarParent,
45
45
  Parent,
46
46
  } from './guards';
47
47
  import {
@@ -52,12 +52,6 @@ import {
52
52
  StructuredTextCustomMark,
53
53
  } from '.';
54
54
 
55
- type Field = SchemaTypes.Field;
56
- type Item = SchemaTypes.Item;
57
- type ItemCreateSchema = SchemaTypes.ItemCreateSchema;
58
- type ItemType = SchemaTypes.ItemType;
59
- type ItemUpdateSchema = SchemaTypes.ItemUpdateSchema;
60
-
61
55
  export type SizingUtilities = {
62
56
  /**
63
57
  * Listens for DOM changes and automatically calls `setHeight` when it detects
@@ -88,8 +82,6 @@ export type RenderAssetSourceCtx = RenderAssetSourcePropertiesAndMethods &
88
82
  SizingUtilities;
89
83
  export type RenderItemFormSidebarPanelCtx =
90
84
  RenderSidebarPanelPropertiesAndMethods & SizingUtilities;
91
- export type RenderItemFormSidebarCtx = RenderSidebarPropertiesAndMethods &
92
- SizingUtilities;
93
85
  export type RenderItemFormOutletCtx = RenderItemFormOutletPropertiesAndMethods &
94
86
  SizingUtilities;
95
87
  export type RenderFieldExtensionCtx = RenderFieldExtensionPropertiesAndMethods &
@@ -155,29 +147,6 @@ export type FullConnectParameters = {
155
147
  ctx: OnBootCtx,
156
148
  ) => MaybePromise<boolean>;
157
149
 
158
- /**
159
- * Use this function to customize the presentation of a record in records
160
- * collections and "Single link" or "Multiple links" field
161
- *
162
- * @tag presentation
163
- */
164
- buildItemPresentationInfo: (
165
- item: Item,
166
- ctx: OnBootCtx,
167
- ) => MaybePromise<ItemPresentationInfo | undefined>;
168
-
169
- /**
170
- * Use this function to customize the initial filters when opening an record
171
- * selector via a "Single link" or "Multiple links" field
172
- *
173
- * @tag locationQuery
174
- */
175
- initialLocationQueryForItemSelector: (
176
- openerfield: Item,
177
- itemType: ItemType,
178
- ctx: OnBootCtx,
179
- ) => MaybePromise<InitialLocationQueryForItemSelector | undefined>;
180
-
181
150
  /**
182
151
  * Use this function to declare new tabs you want to add in the top-bar of the
183
152
  * UI
@@ -226,14 +195,6 @@ export type FullConnectParameters = {
226
195
  ctx: IntentCtx,
227
196
  ) => ItemFormSidebarPanel[];
228
197
 
229
- /**
230
- * Use this function to declare new sidebar to be shown when the user edits
231
- * records of a particular model
232
- *
233
- * @tag sidebarPanels
234
- */
235
- itemFormSidebars: (itemType: ItemType, ctx: IntentCtx) => ItemFormSidebar[];
236
-
237
198
  /**
238
199
  * Use this function to declare custom outlets to be shown at the top of the
239
200
  * record's editing page
@@ -307,16 +268,6 @@ export type FullConnectParameters = {
307
268
  sidebarPaneId: string,
308
269
  ctx: RenderItemFormSidebarPanelCtx,
309
270
  ) => void;
310
- /**
311
- * This function will be called when the plugin needs to render a sidebar (see
312
- * the `itemFormSidebars` function)
313
- *
314
- * @tag sidebarPanels
315
- */
316
- renderItemFormSidebar: (
317
- sidebarId: string,
318
- ctx: RenderItemFormSidebarCtx,
319
- ) => void;
320
271
  /**
321
272
  * This function will be called when the plugin needs to render an outlet (see
322
273
  * the `itemFormOutlets` function)
@@ -406,7 +357,9 @@ const buildRenderUtils = (parent: { setHeight: (number: number) => void }) => {
406
357
  ? Math.max(
407
358
  document.body.scrollHeight,
408
359
  document.body.offsetHeight,
409
- document.documentElement.getBoundingClientRect().height,
360
+ document.documentElement.clientHeight,
361
+ document.documentElement.scrollHeight,
362
+ document.documentElement.offsetHeight,
410
363
  )
411
364
  : height;
412
365
 
@@ -417,39 +370,29 @@ const buildRenderUtils = (parent: { setHeight: (number: number) => void }) => {
417
370
  };
418
371
 
419
372
  let resizeObserver: ResizeObserver | null = null;
420
- let mutationObserver: MutationObserver | null = null;
421
- const onMutation = () => updateHeight();
422
373
 
423
374
  const startAutoResizer = () => {
424
375
  updateHeight();
425
376
 
426
- if (!resizeObserver) {
427
- resizeObserver = new ResizeObserver(onMutation);
428
- resizeObserver.observe(document.documentElement);
377
+ if (resizeObserver) {
378
+ return;
429
379
  }
430
380
 
431
- if (!mutationObserver) {
432
- mutationObserver = new MutationObserver(onMutation);
381
+ resizeObserver = new ResizeObserver(() => {
382
+ // entries[entries.length - 1].borderBoxSize[0].blockSize;
383
+ updateHeight();
384
+ });
433
385
 
434
- mutationObserver.observe(window.document.body, {
435
- attributes: true,
436
- childList: true,
437
- subtree: true,
438
- characterData: true,
439
- });
440
- }
386
+ resizeObserver.observe(document.documentElement);
441
387
  };
442
388
 
443
389
  const stopAutoResizer = () => {
444
- if (resizeObserver) {
445
- resizeObserver.disconnect();
446
- resizeObserver = null;
390
+ if (!resizeObserver) {
391
+ return;
447
392
  }
448
393
 
449
- if (mutationObserver) {
450
- mutationObserver.disconnect();
451
- mutationObserver = null;
452
- }
394
+ resizeObserver.disconnect();
395
+ resizeObserver = null;
453
396
  };
454
397
 
455
398
  return { updateHeight, startAutoResizer, stopAutoResizer };
@@ -465,7 +408,6 @@ export async function connect(
465
408
  contentAreaSidebarItems,
466
409
  manualFieldExtensions,
467
410
  itemFormSidebarPanels,
468
- itemFormSidebars,
469
411
  itemFormOutlets,
470
412
  } = configuration;
471
413
  // rome-ignore lint/suspicious/noExplicitAny: <explanation>
@@ -497,7 +439,6 @@ export async function connect(
497
439
  contentAreaSidebarItems,
498
440
  manualFieldExtensions,
499
441
  itemFormSidebarPanels,
500
- itemFormSidebars,
501
442
  itemFormOutlets,
502
443
  overrideFieldExtensions: toMultifield(
503
444
  configuration.overrideFieldExtensions,
@@ -668,27 +609,6 @@ export async function connect(
668
609
  render(initialSettings as Settings);
669
610
  }
670
611
 
671
- if (isRenderSidebarParent(parent, initialSettings)) {
672
- type Settings = AwaitedReturnType<RenderSidebarMethods['getSettings']>;
673
-
674
- const renderUtils = buildRenderUtils(parent);
675
-
676
- const render = (settings: Settings) => {
677
- if (!configuration.renderItemFormSidebar) {
678
- return;
679
- }
680
-
681
- configuration.renderItemFormSidebar(settings.sidebarId, {
682
- ...parent,
683
- ...settings,
684
- ...renderUtils,
685
- });
686
- };
687
-
688
- listener = render;
689
- render(initialSettings as Settings);
690
- }
691
-
692
612
  if (isRenderItemFormOutletParent(parent, initialSettings)) {
693
613
  type Settings = AwaitedReturnType<
694
614
  RenderItemFormOutletMethods['getSettings']
package/src/guards.ts CHANGED
@@ -8,7 +8,6 @@ import {
8
8
  RenderSidebarPanelMethods,
9
9
  RenderModalMethods,
10
10
  RenderAssetSourceMethods,
11
- RenderSidebarMethods,
12
11
  } from './types';
13
12
 
14
13
  export type Parent = { getSettings: () => Promise<{ mode: string }> };
@@ -32,10 +31,6 @@ export const isRenderSidebarPanelParent = buildGuard<RenderSidebarPanelMethods>(
32
31
  'renderItemFormSidebarPanel',
33
32
  );
34
33
 
35
- export const isRenderSidebarParent = buildGuard<RenderSidebarMethods>(
36
- 'renderItemFormSidebar',
37
- );
38
-
39
34
  export const isRenderItemFormOutletParent =
40
35
  buildGuard<RenderItemFormOutletMethods>('renderItemFormOutlet');
41
36
 
package/src/index.ts CHANGED
@@ -1,15 +1,15 @@
1
- import { SchemaTypes } from '@datocms/cma-client';
2
-
3
- type Account = SchemaTypes.Account;
4
- type Field = SchemaTypes.Field;
5
- type Item = SchemaTypes.Item;
6
- type ItemType = SchemaTypes.ItemType;
7
- type Plugin = SchemaTypes.Plugin;
8
- type Site = SchemaTypes.Site;
9
- type SsoUser = SchemaTypes.SsoUser;
10
- type Upload = SchemaTypes.Upload;
11
- type User = SchemaTypes.User;
12
- type Role = SchemaTypes.Role;
1
+ import {
2
+ Account,
3
+ Field,
4
+ Item,
5
+ ItemType,
6
+ Plugin,
7
+ Site,
8
+ SsoUser,
9
+ Upload,
10
+ User,
11
+ Role,
12
+ } from './SiteApiSchema';
13
13
 
14
14
  export type {
15
15
  Account,