@contentful/app-sdk 4.23.0-alpha.1 → 5.0.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.
- package/README.md +6 -15
- package/dist/api.js +109 -0
- package/dist/app.js +99 -0
- package/dist/channel.js +111 -0
- package/dist/cma.js +16 -0
- package/dist/cmaAdapter.js +12 -0
- package/dist/dialogs.js +37 -0
- package/dist/editor.js +29 -0
- package/dist/entry.js +60 -0
- package/dist/field-locale.js +70 -0
- package/dist/field.js +77 -0
- package/dist/index.js +23 -0
- package/dist/initialize.js +64 -0
- package/dist/locations.js +13 -0
- package/dist/navigator.js +62 -0
- package/dist/signal.js +51 -0
- package/dist/types/api.types.d.ts +2 -34
- package/dist/types/api.types.js +2 -0
- package/dist/types/app.types.d.ts +0 -4
- package/dist/types/app.types.js +2 -0
- package/dist/types/cmaClient.types.d.ts +0 -1
- package/dist/types/cmaClient.types.js +2 -0
- package/dist/types/dialogs.types.d.ts +1 -5
- package/dist/types/dialogs.types.js +2 -0
- package/dist/types/entities.js +2 -0
- package/dist/types/entry.types.d.ts +0 -5
- package/dist/types/entry.types.js +2 -0
- package/dist/types/field-locale.types.js +2 -0
- package/dist/types/field.types.js +2 -0
- package/dist/types/index.d.ts +2 -3
- package/dist/types/index.js +2 -0
- package/dist/types/navigator.types.d.ts +13 -11
- package/dist/types/navigator.types.js +2 -0
- package/dist/types/utils.js +2 -0
- package/dist/types/validation-error.js +2 -0
- package/dist/types/window.types.js +2 -0
- package/dist/utils/deferred.js +20 -0
- package/dist/window.js +106 -0
- package/package.json +118 -1
- package/dist/README.md +0 -9
- package/dist/cf-extension-api.bundled.js +0 -1
- package/dist/cf-extension-api.js +0 -1
- package/dist/cf-extension.css +0 -600
- package/dist/space.d.ts +0 -3
- package/dist/types/space.types.d.ts +0 -272
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.init = exports.locations = void 0;
|
|
18
|
+
const initialize_1 = require("./initialize");
|
|
19
|
+
const api_1 = require("./api");
|
|
20
|
+
__exportStar(require("./types"), exports);
|
|
21
|
+
var locations_1 = require("./locations");
|
|
22
|
+
Object.defineProperty(exports, "locations", { enumerable: true, get: function () { return locations_1.default; } });
|
|
23
|
+
exports.init = (0, initialize_1.createInitializer)(globalThis, api_1.default);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createInitializer = void 0;
|
|
4
|
+
const channel_1 = require("./channel");
|
|
5
|
+
const deferred_1 = require("./utils/deferred");
|
|
6
|
+
function createInitializer(currentGlobal, apiCreator) {
|
|
7
|
+
if (typeof currentGlobal.window === 'undefined' ||
|
|
8
|
+
typeof currentGlobal.document === 'undefined') {
|
|
9
|
+
// make `init` a noop if window or document is not available
|
|
10
|
+
return () => { };
|
|
11
|
+
}
|
|
12
|
+
const connectDeferred = (0, deferred_1.createDeferred)();
|
|
13
|
+
connectDeferred.promise.then(([channel]) => {
|
|
14
|
+
const { document } = currentGlobal;
|
|
15
|
+
document.addEventListener('focus', () => channel.send('setActive', true), true);
|
|
16
|
+
document.addEventListener('blur', () => channel.send('setActive', false), true);
|
|
17
|
+
});
|
|
18
|
+
// We need to connect right away so we can record incoming
|
|
19
|
+
// messages before `init` is called.
|
|
20
|
+
(0, channel_1.connect)(currentGlobal, (...args) => connectDeferred.resolve(args));
|
|
21
|
+
let initializedSdks;
|
|
22
|
+
return function init(initCb, { makeCustomApi, supressIframeWarning, } = {
|
|
23
|
+
supressIframeWarning: false,
|
|
24
|
+
}) {
|
|
25
|
+
if (!supressIframeWarning) {
|
|
26
|
+
warnIfOutsideOfContentful(currentGlobal);
|
|
27
|
+
}
|
|
28
|
+
if (!initializedSdks) {
|
|
29
|
+
initializedSdks = connectDeferred.promise.then(([channel, params, messageQueue]) => {
|
|
30
|
+
const api = apiCreator(channel, params, currentGlobal);
|
|
31
|
+
let customApi;
|
|
32
|
+
if (typeof makeCustomApi === 'function') {
|
|
33
|
+
customApi = makeCustomApi(channel, params);
|
|
34
|
+
}
|
|
35
|
+
// Handle pending incoming messages.
|
|
36
|
+
// APIs are created before so handlers are already
|
|
37
|
+
// registered on the channel.
|
|
38
|
+
messageQueue.forEach((m) => {
|
|
39
|
+
// TODO Expose private handleMessage method
|
|
40
|
+
;
|
|
41
|
+
channel._handleMessage(m);
|
|
42
|
+
});
|
|
43
|
+
return [api, customApi];
|
|
44
|
+
});
|
|
45
|
+
if (!connectDeferred.isFulfilled) {
|
|
46
|
+
(0, channel_1.sendInitMessage)(currentGlobal);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
initializedSdks.then(([sdk, customSdk]) =>
|
|
50
|
+
// Hand over control to the developer.
|
|
51
|
+
initCb(sdk, customSdk));
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
exports.createInitializer = createInitializer;
|
|
55
|
+
function warnIfOutsideOfContentful(currentGlobal) {
|
|
56
|
+
if (currentGlobal.self === currentGlobal.top) {
|
|
57
|
+
console.error(`Cannot use App SDK outside of Contenful:
|
|
58
|
+
|
|
59
|
+
In order for the App SDK to function correctly, your app needs to be run in an iframe in the Contentful Web App, Compose or Launch.
|
|
60
|
+
|
|
61
|
+
Learn more about local development with the App SDK here:
|
|
62
|
+
https://www.contentful.com/developers/docs/extensibility/ui-extensions/faq/#how-can-i-develop-with-the-ui-extension-sdk-locally`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const locations = {
|
|
4
|
+
LOCATION_ENTRY_FIELD: 'entry-field',
|
|
5
|
+
LOCATION_ENTRY_FIELD_SIDEBAR: 'entry-field-sidebar',
|
|
6
|
+
LOCATION_ENTRY_SIDEBAR: 'entry-sidebar',
|
|
7
|
+
LOCATION_DIALOG: 'dialog',
|
|
8
|
+
LOCATION_ENTRY_EDITOR: 'entry-editor',
|
|
9
|
+
LOCATION_PAGE: 'page',
|
|
10
|
+
LOCATION_APP_CONFIG: 'app-config',
|
|
11
|
+
LOCATION_HOME: 'home',
|
|
12
|
+
};
|
|
13
|
+
exports.default = locations;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const signal_1 = require("./signal");
|
|
4
|
+
function createNavigator(channel, ids) {
|
|
5
|
+
const _onSlideInSignal = new signal_1.Signal();
|
|
6
|
+
channel.addHandler('navigateSlideIn', (data) => {
|
|
7
|
+
_onSlideInSignal.dispatch(data);
|
|
8
|
+
});
|
|
9
|
+
return {
|
|
10
|
+
openEntry: (id, opts) => {
|
|
11
|
+
return channel.call('navigateToContentEntity', {
|
|
12
|
+
...opts,
|
|
13
|
+
entityType: 'Entry',
|
|
14
|
+
id,
|
|
15
|
+
});
|
|
16
|
+
},
|
|
17
|
+
openNewEntry: (contentTypeId, opts) => {
|
|
18
|
+
return channel.call('navigateToContentEntity', {
|
|
19
|
+
...opts,
|
|
20
|
+
entityType: 'Entry',
|
|
21
|
+
id: null,
|
|
22
|
+
contentTypeId,
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
openBulkEditor: (entryId, opts) => {
|
|
26
|
+
return channel.call('navigateToBulkEditor', {
|
|
27
|
+
entryId,
|
|
28
|
+
...opts,
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
openAsset: (id, opts) => {
|
|
32
|
+
return channel.call('navigateToContentEntity', {
|
|
33
|
+
...opts,
|
|
34
|
+
entityType: 'Asset',
|
|
35
|
+
id,
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
openNewAsset: (opts) => {
|
|
39
|
+
return channel.call('navigateToContentEntity', {
|
|
40
|
+
...opts,
|
|
41
|
+
entityType: 'Asset',
|
|
42
|
+
id: null,
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
openPage: (opts) => {
|
|
46
|
+
return channel.call('navigateToPage', { type: 'app', id: ids.app, ...opts });
|
|
47
|
+
},
|
|
48
|
+
openAppConfig: () => {
|
|
49
|
+
return channel.call('navigateToAppConfig');
|
|
50
|
+
},
|
|
51
|
+
openEntriesList: (options = {}) => {
|
|
52
|
+
return channel.call('navigateToSpaceEnvRoute', { route: 'entries', options });
|
|
53
|
+
},
|
|
54
|
+
openAssetsList: (options = {}) => {
|
|
55
|
+
return channel.call('navigateToSpaceEnvRoute', { route: 'assets', options });
|
|
56
|
+
},
|
|
57
|
+
onSlideInNavigation: (handler) => {
|
|
58
|
+
return _onSlideInSignal.attach(handler);
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
exports.default = createNavigator;
|
package/dist/signal.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MemoizedSignal = exports.Signal = void 0;
|
|
4
|
+
class Signal {
|
|
5
|
+
constructor() {
|
|
6
|
+
this._id = 0;
|
|
7
|
+
this._listeners = {};
|
|
8
|
+
}
|
|
9
|
+
dispatch(...args) {
|
|
10
|
+
for (const key in this._listeners) {
|
|
11
|
+
this._listeners[key](...args);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
attach(listener) {
|
|
15
|
+
if (typeof listener !== 'function') {
|
|
16
|
+
throw new Error('listener function expected');
|
|
17
|
+
}
|
|
18
|
+
const id = this._id++;
|
|
19
|
+
this._listeners[id] = listener;
|
|
20
|
+
// return function that'll detach the listener
|
|
21
|
+
return () => delete this._listeners[id];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.Signal = Signal;
|
|
25
|
+
class MemoizedSignal extends Signal {
|
|
26
|
+
constructor(...memoizedArgs) {
|
|
27
|
+
super();
|
|
28
|
+
if (!memoizedArgs.length) {
|
|
29
|
+
throw new Error('Initial value to be memoized expected');
|
|
30
|
+
}
|
|
31
|
+
this._memoizedArgs = memoizedArgs;
|
|
32
|
+
}
|
|
33
|
+
dispatch(...args) {
|
|
34
|
+
this._memoizedArgs = args;
|
|
35
|
+
super.dispatch(...args);
|
|
36
|
+
}
|
|
37
|
+
attach(listener) {
|
|
38
|
+
/*
|
|
39
|
+
* attaching first so that we throw a sensible
|
|
40
|
+
* error if listener is not a function without
|
|
41
|
+
* duplication of is function check
|
|
42
|
+
*/
|
|
43
|
+
const detachListener = super.attach(listener);
|
|
44
|
+
listener(...this._memoizedArgs);
|
|
45
|
+
return detachListener;
|
|
46
|
+
}
|
|
47
|
+
getMemoizedArgs() {
|
|
48
|
+
return this._memoizedArgs;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.MemoizedSignal = MemoizedSignal;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ContentType, EditorInterface, SpaceMembership, Role, ContentTypeField, Metadata, Entry, Task, Asset, WorkflowDefinition } from './entities';
|
|
2
2
|
import { EntryAPI } from './entry.types';
|
|
3
|
-
import { SpaceAPI } from './space.types';
|
|
4
3
|
import { WindowAPI } from './window.types';
|
|
5
4
|
import { EntrySys, Link, SerializedJSONValue } from './utils';
|
|
6
5
|
import { FieldAPI } from './field-locale.types';
|
|
@@ -77,9 +76,8 @@ export interface ParametersAPI<InstallationParameters extends KeyValueMap, Insta
|
|
|
77
76
|
}
|
|
78
77
|
export interface IdsAPI {
|
|
79
78
|
user: string;
|
|
80
|
-
extension?: string;
|
|
81
79
|
organization: string;
|
|
82
|
-
app
|
|
80
|
+
app: string;
|
|
83
81
|
space: string;
|
|
84
82
|
environment: string;
|
|
85
83
|
environmentAlias?: string;
|
|
@@ -124,14 +122,6 @@ export interface SharedEditorSDK {
|
|
|
124
122
|
* @returns Function to unsubscribe. `callback` won't be called anymore.
|
|
125
123
|
*/
|
|
126
124
|
onLocaleSettingsChanged: (callback: (localeSettings: EditorLocaleSettings) => void) => () => void;
|
|
127
|
-
/**
|
|
128
|
-
* Subscribes to changes of whether or not disabled fields are displayed
|
|
129
|
-
*
|
|
130
|
-
* @param callback Function that is called every time the setting whether or not disabled fields are displayed changes. Called immediately with the current state.
|
|
131
|
-
* @returns Function to unsubscribe. `callback` won't be called anymore.
|
|
132
|
-
* @deprecated Use {@link onShowHiddenFieldsChanged} instead
|
|
133
|
-
*/
|
|
134
|
-
onShowDisabledFieldsChanged: (callback: (showDisabledFields: boolean) => void) => () => void;
|
|
135
125
|
/**
|
|
136
126
|
* Returns whether or not hidden fields are displayed
|
|
137
127
|
*
|
|
@@ -175,10 +165,6 @@ export interface AccessAPI {
|
|
|
175
165
|
}
|
|
176
166
|
type EntryScopedIds = 'field' | 'entry' | 'contentType';
|
|
177
167
|
export interface BaseAppSDK<InstallationParameters extends KeyValueMap = KeyValueMap, InstanceParameters extends KeyValueMap = KeyValueMap, InvocationParameters extends SerializedJSONValue = SerializedJSONValue> {
|
|
178
|
-
/** @deprecated since version 4.0.0 consider using the CMA instead
|
|
179
|
-
* See https://www.contentful.com/developers/docs/extensibility/app-framework/sdk/#using-the-contentful-management-library for more details
|
|
180
|
-
*/
|
|
181
|
-
space: SpaceAPI;
|
|
182
168
|
/** Information about the current user and roles */
|
|
183
169
|
user: UserAPI;
|
|
184
170
|
/** Information about the current locales */
|
|
@@ -239,30 +225,12 @@ export type HomeAppSDK<InstallationParameters extends KeyValueMap = KeyValueMap>
|
|
|
239
225
|
};
|
|
240
226
|
export type ConfigAppSDK<InstallationParameters extends KeyValueMap = KeyValueMap> = Omit<BaseAppSDK<InstallationParameters, never, never>, 'ids'> & {
|
|
241
227
|
/** A set of IDs actual for the app */
|
|
242
|
-
ids: Omit<IdsAPI, EntryScopedIds | '
|
|
228
|
+
ids: Omit<IdsAPI, EntryScopedIds | 'app'> & {
|
|
243
229
|
app: string;
|
|
244
230
|
};
|
|
245
231
|
app: AppConfigAPI;
|
|
246
232
|
};
|
|
247
233
|
export type KnownAppSDK<InstallationParameters extends KeyValueMap = KeyValueMap, InstanceParameters extends KeyValueMap = KeyValueMap, InvocationParameters extends SerializedJSONValue = SerializedJSONValue> = FieldAppSDK<InstallationParameters, InstanceParameters> | SidebarAppSDK<InstallationParameters, InstanceParameters> | DialogAppSDK<InstallationParameters, InvocationParameters> | EditorAppSDK<InstallationParameters, InstanceParameters> | PageAppSDK<InstallationParameters> | ConfigAppSDK<InstallationParameters> | HomeAppSDK<InstallationParameters>;
|
|
248
|
-
/** @deprecated consider using {@link BaseAppSDK} */
|
|
249
|
-
export type BaseExtensionSDK = BaseAppSDK;
|
|
250
|
-
/** @deprecated consider using {@link EditorAppSDK} */
|
|
251
|
-
export type EditorExtensionSDK = EditorAppSDK;
|
|
252
|
-
/** @deprecated consider using {@link SidebarAppSDK} */
|
|
253
|
-
export type SidebarExtensionSDK = SidebarAppSDK;
|
|
254
|
-
/** @deprecated consider using {@link FieldAppSDK} */
|
|
255
|
-
export type FieldExtensionSDK = FieldAppSDK;
|
|
256
|
-
/** @deprecated consider using {@link DialogAppSDK} */
|
|
257
|
-
export type DialogExtensionSDK = DialogAppSDK;
|
|
258
|
-
/** @deprecated consider using {@link PageAppSDK} */
|
|
259
|
-
export type PageExtensionSDK = PageAppSDK;
|
|
260
|
-
/** @deprecated consider using {@link HomeAppSDK} */
|
|
261
|
-
export type HomeExtensionSDK = HomeAppSDK;
|
|
262
|
-
/** @deprecated consider using {@link ConfigAppSDK} */
|
|
263
|
-
export type AppExtensionSDK = ConfigAppSDK;
|
|
264
|
-
/** @deprecated consider using {@link KnownAppSDK} */
|
|
265
|
-
export type KnownSDK = KnownAppSDK;
|
|
266
234
|
export interface ConnectMessage {
|
|
267
235
|
id: string;
|
|
268
236
|
location: Locations[keyof Locations];
|
|
@@ -12,10 +12,6 @@ interface AppStateEditorInterfaceItem {
|
|
|
12
12
|
position: number;
|
|
13
13
|
settings?: Record<string, any>;
|
|
14
14
|
};
|
|
15
|
-
/**
|
|
16
|
-
* @deprecated use `editors` instead
|
|
17
|
-
*/
|
|
18
|
-
editor?: boolean;
|
|
19
15
|
}
|
|
20
16
|
export interface AppState {
|
|
21
17
|
EditorInterface: Record<ContentType['sys']['id'], AppStateEditorInterfaceItem>;
|
|
@@ -20,7 +20,6 @@ export type CMAClient = {
|
|
|
20
20
|
role: Pick<PlainClientAPI['role'], 'get' | 'getMany'>;
|
|
21
21
|
scheduledActions: PlainClientAPI['scheduledActions'];
|
|
22
22
|
snapshot: PlainClientAPI['snapshot'];
|
|
23
|
-
space: Pick<PlainClientAPI['space'], 'get'>;
|
|
24
23
|
upload: PlainClientAPI['upload'];
|
|
25
24
|
user: Pick<PlainClientAPI['user'], 'getManyForSpace' | 'getForSpace'>;
|
|
26
25
|
usage: Pick<PlainClientAPI['usage'], 'getManyForSpace'>;
|
|
@@ -36,12 +36,8 @@ export interface DialogsAPI {
|
|
|
36
36
|
openPrompt: (options: OpenConfirmOptions & {
|
|
37
37
|
defaultValue?: string;
|
|
38
38
|
}) => Promise<string | boolean>;
|
|
39
|
-
/** Opens an extension in a dialog. */
|
|
40
|
-
openExtension: (options: OpenCustomWidgetOptions) => Promise<any>;
|
|
41
39
|
/** Opens the current app in a dialog */
|
|
42
|
-
|
|
43
|
-
/** Opens the current app or extension in a dialog */
|
|
44
|
-
openCurrent: (options?: Omit<OpenCustomWidgetOptions, 'id'> | OpenCustomWidgetOptions) => Promise<any>;
|
|
40
|
+
open: (options?: Omit<OpenCustomWidgetOptions, 'id'>) => Promise<any>;
|
|
45
41
|
/** Opens a dialog for selecting a single entry. */
|
|
46
42
|
selectSingleEntry: <T = Object>(options?: {
|
|
47
43
|
locale?: string;
|
|
@@ -34,11 +34,6 @@ export interface EntryAPI extends TaskAPI {
|
|
|
34
34
|
fields: {
|
|
35
35
|
[key: string]: EntryFieldAPI;
|
|
36
36
|
};
|
|
37
|
-
/**
|
|
38
|
-
* Optional metadata on an entry
|
|
39
|
-
* @deprecated
|
|
40
|
-
*/
|
|
41
|
-
metadata?: Metadata;
|
|
42
37
|
getMetadata: () => Metadata | undefined;
|
|
43
38
|
onMetadataChanged: (callback: (metadata?: Metadata) => void) => VoidFunction;
|
|
44
39
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
export type {
|
|
1
|
+
export type { ConfigAppSDK, BaseAppSDK, DialogAppSDK, EditorAppSDK, FieldAppSDK, HomeAppSDK, KnownAppSDK, PageAppSDK, SidebarAppSDK, AccessAPI, ArchiveableAction, ConnectMessage, ContentTypeAPI, CrudAction, EditorLocaleSettings, IdsAPI, LocalesAPI, LocationAPI, Locations, NotifierAPI, ParametersAPI, PublishableAction, SharedEditorSDK, UserAPI, JSONPatchItem, } from './api.types';
|
|
2
2
|
export type { AppConfigAPI, AppState, OnConfigureHandler, OnConfigureHandlerReturn, } from './app.types';
|
|
3
3
|
export type { DialogsAPI, EntityDialogOptions, OpenAlertOptions, OpenConfirmOptions, OpenCustomWidgetOptions, } from './dialogs.types';
|
|
4
4
|
export type { Asset, CanonicalRequest, ContentType, ContentTypeField, EditorInterface, Entry, Metadata, Role, ScheduledAction, SpaceMembership, Tag, TagVisibility, Task, Team, User, WorkflowDefinition, } from './entities';
|
|
5
5
|
export type { EntryAPI, TaskAPI, TaskInputData } from './entry.types';
|
|
6
6
|
export type { FieldInfo, EntryFieldInfo, EntryFieldAPI } from './field.types';
|
|
7
7
|
export type { FieldAPI } from './field-locale.types';
|
|
8
|
-
export type { NavigatorAPI, AppPageLocationOptions, NavigatorAPIOptions, NavigatorOpenResponse, NavigatorPageResponse, NavigatorSlideInfo,
|
|
9
|
-
export type { SpaceAPI } from './space.types';
|
|
8
|
+
export type { NavigatorAPI, AppPageLocationOptions, NavigatorAPIOptions, NavigatorOpenResponse, NavigatorPageResponse, NavigatorSlideInfo, } from './navigator.types';
|
|
10
9
|
export type { SearchQuery, CollectionResponse, EntrySys, ContentEntitySys, ContentEntityType, FieldType, FieldLinkType, Items, Link, WithOptionalId, WithId, SerializedJSONValue, } from './utils';
|
|
11
10
|
export type { DateRangeValidationError, InValidationError, LinkContentTypeValidationError, LinkMimetypeGroupValidationError, NotResolvableValidationError, ProhibitRegexpValidationError, RangeValidationError, RegexpValidationError, RequiredValidationError, SizeValidationError, TypeValidationError, UniqueValidationError, UnknownValidationError, ValidationError, } from './validation-error';
|
|
12
11
|
export type { WindowAPI } from './window.types';
|
|
@@ -5,16 +5,20 @@ export interface NavigatorAPIOptions {
|
|
|
5
5
|
waitForClose: boolean;
|
|
6
6
|
};
|
|
7
7
|
}
|
|
8
|
-
export interface PageExtensionOptions {
|
|
9
|
-
/** If included, you can navigate to a different page extension. If omitted, you will navigate within the current extension. */
|
|
10
|
-
id?: string;
|
|
11
|
-
/** Navigate to a path within your page extension. */
|
|
12
|
-
path?: string;
|
|
13
|
-
}
|
|
14
8
|
export interface AppPageLocationOptions {
|
|
15
9
|
/** A path to navigate to within your app's page location. */
|
|
16
10
|
path?: string;
|
|
17
11
|
}
|
|
12
|
+
export interface OpenEntriesListOptions {
|
|
13
|
+
filters?: {
|
|
14
|
+
contentType?: string;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export interface OpenAssetsListOptions {
|
|
18
|
+
filters?: {
|
|
19
|
+
type?: 'attachment' | 'plaintext' | 'image' | 'audio' | 'video' | 'richtext' | 'presentation' | 'spreadsheet' | 'pdfdocument' | 'archive' | 'code' | 'markup';
|
|
20
|
+
};
|
|
21
|
+
}
|
|
18
22
|
/** Information about current value of the navigation status. */
|
|
19
23
|
export interface NavigatorPageResponse {
|
|
20
24
|
/** Will be true if navigation was successfully executed by the web app. */
|
|
@@ -40,10 +44,8 @@ export interface NavigatorAPI {
|
|
|
40
44
|
openNewEntry: <Fields extends KeyValueMap = KeyValueMap>(contentTypeId: string, options?: NavigatorAPIOptions) => Promise<NavigatorOpenResponse<Entry<Fields>>>;
|
|
41
45
|
/** Opens a new asset in the current Web App session. */
|
|
42
46
|
openNewAsset: (options?: NavigatorAPIOptions) => Promise<NavigatorOpenResponse<Asset>>;
|
|
43
|
-
/** Navigates to a page extension in the current Web App session. Calling without `options` will navigate to the home route of your page extension. */
|
|
44
|
-
openPageExtension: (options?: PageExtensionOptions) => Promise<NavigatorPageResponse>;
|
|
45
47
|
/** Navigates to the app's page location. */
|
|
46
|
-
|
|
48
|
+
openPage: (options?: AppPageLocationOptions) => Promise<NavigatorPageResponse>;
|
|
47
49
|
/** Navigates to a bulk entry editor */
|
|
48
50
|
openBulkEditor: (entryId: string, options: {
|
|
49
51
|
/** ID of the reference field */
|
|
@@ -57,7 +59,7 @@ export interface NavigatorAPI {
|
|
|
57
59
|
slide?: NavigatorSlideInfo;
|
|
58
60
|
}>;
|
|
59
61
|
openAppConfig: () => Promise<void>;
|
|
60
|
-
openEntriesList: () => Promise<void>;
|
|
61
|
-
openAssetsList: () => Promise<void>;
|
|
62
|
+
openEntriesList: (options?: OpenEntriesListOptions) => Promise<void>;
|
|
63
|
+
openAssetsList: (options?: OpenAssetsListOptions) => Promise<void>;
|
|
62
64
|
onSlideInNavigation: (fn: (slide: NavigatorSlideInfo) => void) => () => void;
|
|
63
65
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDeferred = void 0;
|
|
4
|
+
function createDeferred() {
|
|
5
|
+
const deferred = {
|
|
6
|
+
// @ts-expect-error Immediately set below
|
|
7
|
+
promise: null,
|
|
8
|
+
// @ts-expect-error Promise executor is immdiately executed and sets `resolve`
|
|
9
|
+
resolve: null,
|
|
10
|
+
isFulfilled: false,
|
|
11
|
+
};
|
|
12
|
+
deferred.promise = new Promise((resolve) => {
|
|
13
|
+
deferred.resolve = (...args) => {
|
|
14
|
+
deferred.isFulfilled = true;
|
|
15
|
+
resolve(...args);
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
return deferred;
|
|
19
|
+
}
|
|
20
|
+
exports.createDeferred = createDeferred;
|
package/dist/window.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function createWindow(currentGlobal, channel) {
|
|
4
|
+
const { document, MutationObserver, ResizeObserver } = currentGlobal;
|
|
5
|
+
let oldHeight;
|
|
6
|
+
let isAutoResizing = false;
|
|
7
|
+
let checkAbsoluteElements = false;
|
|
8
|
+
const absolutePositionedElems = new Set();
|
|
9
|
+
const mutationObserver = new MutationObserver((mutations) => {
|
|
10
|
+
checkAbsolutePositionedElems(mutations);
|
|
11
|
+
if (isAutoResizing) {
|
|
12
|
+
self.updateHeight();
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
16
|
+
self.updateHeight();
|
|
17
|
+
});
|
|
18
|
+
mutationObserver.observe(document.body, {
|
|
19
|
+
attributes: true,
|
|
20
|
+
childList: true,
|
|
21
|
+
subtree: true,
|
|
22
|
+
characterData: true,
|
|
23
|
+
});
|
|
24
|
+
const self = { startAutoResizer, stopAutoResizer, updateHeight };
|
|
25
|
+
return self;
|
|
26
|
+
function checkAbsoluteElementStyle(type, element) {
|
|
27
|
+
const computedStyle = getComputedStyle(element);
|
|
28
|
+
if (computedStyle.position !== 'absolute') {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
switch (type) {
|
|
32
|
+
case 'attributes':
|
|
33
|
+
return computedStyle.display !== 'none';
|
|
34
|
+
default:
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function checkAbsolutePositionedElems(mutations) {
|
|
39
|
+
mutations.forEach((mutation) => {
|
|
40
|
+
switch (mutation.type) {
|
|
41
|
+
case 'attributes':
|
|
42
|
+
if (mutation.target.nodeType === Node.ELEMENT_NODE) {
|
|
43
|
+
const element = mutation.target;
|
|
44
|
+
if (checkAbsoluteElementStyle(mutation.type, element)) {
|
|
45
|
+
absolutePositionedElems.add(element);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
absolutePositionedElems.delete(element);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
break;
|
|
52
|
+
case 'childList':
|
|
53
|
+
mutation.addedNodes.forEach((node) => {
|
|
54
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
55
|
+
const element = node;
|
|
56
|
+
if (checkAbsoluteElementStyle(mutation.type, element)) {
|
|
57
|
+
absolutePositionedElems.add(element);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
mutation.removedNodes.forEach((node) => {
|
|
62
|
+
const element = node;
|
|
63
|
+
absolutePositionedElems.delete(element);
|
|
64
|
+
});
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function startAutoResizer({ absoluteElements = false } = {}) {
|
|
70
|
+
checkAbsoluteElements = Boolean(absoluteElements);
|
|
71
|
+
self.updateHeight();
|
|
72
|
+
if (isAutoResizing) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
isAutoResizing = true;
|
|
76
|
+
resizeObserver.observe(document.body);
|
|
77
|
+
}
|
|
78
|
+
function stopAutoResizer() {
|
|
79
|
+
if (!isAutoResizing) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
isAutoResizing = false;
|
|
83
|
+
resizeObserver.disconnect();
|
|
84
|
+
}
|
|
85
|
+
function updateHeight(height = null) {
|
|
86
|
+
if (height === null) {
|
|
87
|
+
const documentHeight = Math.ceil(document.documentElement.getBoundingClientRect().height);
|
|
88
|
+
// Only check for absolute elements if option is provided to startAutoResizer
|
|
89
|
+
if (checkAbsoluteElements && absolutePositionedElems.size) {
|
|
90
|
+
let maxHeight = documentHeight;
|
|
91
|
+
absolutePositionedElems.forEach((element) => {
|
|
92
|
+
maxHeight = Math.max(element.getBoundingClientRect().bottom, maxHeight);
|
|
93
|
+
});
|
|
94
|
+
height = maxHeight;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
height = documentHeight;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (height !== oldHeight) {
|
|
101
|
+
channel.send('setHeight', height);
|
|
102
|
+
oldHeight = height;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.default = createWindow;
|