@hygraph/app-sdk 0.0.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.
Files changed (46) hide show
  1. package/README.md +15 -0
  2. package/dist/app-sdk.cjs.development.js +167 -0
  3. package/dist/app-sdk.cjs.development.js.map +1 -0
  4. package/dist/app-sdk.cjs.production.min.js +2 -0
  5. package/dist/app-sdk.cjs.production.min.js.map +1 -0
  6. package/dist/app-sdk.esm.js +158 -0
  7. package/dist/app-sdk.esm.js.map +1 -0
  8. package/dist/app-sdk.umd.development.js +171 -0
  9. package/dist/app-sdk.umd.development.js.map +1 -0
  10. package/dist/app-sdk.umd.production.min.js +2 -0
  11. package/dist/app-sdk.umd.production.min.js.map +1 -0
  12. package/dist/app.d.ts +8 -0
  13. package/dist/base.d.ts +56 -0
  14. package/dist/field.d.ts +54 -0
  15. package/dist/formSidebar.d.ts +27 -0
  16. package/dist/index.d.ts +40 -0
  17. package/dist/index.js +8 -0
  18. package/dist/type-helpers/appInstallation.d.ts +11 -0
  19. package/dist/type-helpers/dialog.d.ts +5 -0
  20. package/dist/type-helpers/field.d.ts +12 -0
  21. package/dist/type-helpers/form.d.ts +20 -0
  22. package/dist/type-helpers/locale.d.ts +9 -0
  23. package/dist/type-helpers/model.d.ts +8 -0
  24. package/dist/type-helpers/openAssetPicker.d.ts +13 -0
  25. package/dist/type-helpers/stage.d.ts +12 -0
  26. package/dist/type-helpers/toast.d.ts +14 -0
  27. package/dist/type-helpers/user.d.ts +8 -0
  28. package/dist/type-helpers/visibility.d.ts +5 -0
  29. package/package.json +41 -0
  30. package/src/app.ts +11 -0
  31. package/src/base.ts +93 -0
  32. package/src/declaration.d.ts +2 -0
  33. package/src/field.ts +73 -0
  34. package/src/formSidebar.ts +33 -0
  35. package/src/index.ts +177 -0
  36. package/src/type-helpers/appInstallation.ts +13 -0
  37. package/src/type-helpers/dialog.ts +11 -0
  38. package/src/type-helpers/field.ts +13 -0
  39. package/src/type-helpers/form.ts +44 -0
  40. package/src/type-helpers/locale.ts +10 -0
  41. package/src/type-helpers/model.ts +8 -0
  42. package/src/type-helpers/openAssetPicker.ts +16 -0
  43. package/src/type-helpers/stage.ts +21 -0
  44. package/src/type-helpers/toast.ts +30 -0
  45. package/src/type-helpers/user.ts +9 -0
  46. package/src/type-helpers/visibility.ts +7 -0
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # @hygraph/app-sdk
2
+
3
+ JavaScript SDK for building Apps for Hygraph.
4
+
5
+ ## ⚡ Usage
6
+
7
+ For docs, guides and examples, please visit [our official documentation](https://hygraph.com/docs/).
8
+
9
+ ## 📝 License
10
+
11
+ Licensed under the MIT License.
12
+
13
+ ---
14
+
15
+ Made with 💜 by Hygraph 👋 [join our community](https://slack.hygraph.com/)!
@@ -0,0 +1,167 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
+
7
+ var zoid = _interopDefault(require('@graphcms/zoid/lib/zoid.js'));
8
+
9
+ function _objectWithoutPropertiesLoose(source, excluded) {
10
+ if (source == null) return {};
11
+ var target = {};
12
+ var sourceKeys = Object.keys(source);
13
+ var key, i;
14
+ for (i = 0; i < sourceKeys.length; i++) {
15
+ key = sourceKeys[i];
16
+ if (excluded.indexOf(key) >= 0) continue;
17
+ target[key] = source[key];
18
+ }
19
+ return target;
20
+ }
21
+
22
+ // see https://github.com/krakenjs/zoid/blob/master/src/component/props.js#L53
23
+ var reservedExtensionProps = ['timeout', 'window', 'close', 'focus', 'resize', 'uid', 'cspNonce', 'getParent', 'getParentDomain', 'hide', 'show', 'export', 'onDisplay', 'onRendered', 'onRender', 'onClose', 'onDestroy', 'onResize', 'onFocus', 'onError', 'onProps'];
24
+ (function (ExtensionPermission) {
25
+ ExtensionPermission["INPUT"] = "INPUT";
26
+ ExtensionPermission["FORM"] = "FORM";
27
+ ExtensionPermission["API"] = "API";
28
+ })(exports.ExtensionPermission || (exports.ExtensionPermission = {}));
29
+
30
+ var FieldExtensionType = {
31
+ STRING: 'STRING',
32
+ RICHTEXT: 'RICHTEXT',
33
+ INT: 'INT',
34
+ FLOAT: 'FLOAT',
35
+ BOOLEAN: 'BOOLEAN',
36
+ JSON: 'JSON',
37
+ DATETIME: 'DATETIME',
38
+ DATE: 'DATE',
39
+ LOCATION: 'LOCATION',
40
+ COLOR: 'COLOR',
41
+ ENUMERATION: 'ENUMERATION',
42
+ RELATION: 'RELATION',
43
+ ASSET: 'ASSET',
44
+ UNION: 'UNION'
45
+ };
46
+ var FieldExtensionFeature = {
47
+ FieldRenderer: 'FieldRenderer',
48
+ ListRenderer: 'ListRenderer',
49
+ TableRenderer: 'TableRenderer'
50
+ };
51
+
52
+ var AppInstallationStatus = {
53
+ COMPLETED: 'COMPLETED',
54
+ DISABLED: 'DISABLED',
55
+ PENDING: 'PENDING'
56
+ };
57
+
58
+ var _excluded = ["onProps", "onConnected", "resize"],
59
+ _excluded2 = ["onProps", "onConnected"];
60
+ function handleProps(props) {
61
+ var transformedProps = {};
62
+ Object.keys(props).forEach(function (key) {
63
+ // do not pass down zoid props to the extension
64
+ if (reservedExtensionProps.includes(key)) return;
65
+ // transform props that were prefixed with '_' to bypass zoid reverved props
66
+ if (key.startsWith('_') && reservedExtensionProps.includes(key.replace(/^_/g, ''))) {
67
+ transformedProps[key.replace(/^_/g, '')] = props[key];
68
+ } else {
69
+ transformedProps[key] = props[key];
70
+ }
71
+ });
72
+ return transformedProps;
73
+ }
74
+ function init(_ref) {
75
+ var debug = _ref.debug,
76
+ _ref$onProps = _ref.onProps,
77
+ onProps = _ref$onProps === void 0 ? function () {
78
+ return undefined;
79
+ } : _ref$onProps,
80
+ givenUid = _ref.uid;
81
+ return new Promise(function (resolve, reject) {
82
+ if (typeof window === 'undefined' || typeof window.postMessage === 'undefined') {
83
+ return reject({
84
+ error: 'unsupported_env',
85
+ message: 'Unsupported environment: Not in a browser supporting PostMessage'
86
+ });
87
+ }
88
+ var uid = givenUid || typeof URLSearchParams !== 'undefined' && new URLSearchParams(window.location.search).get('extensionUid');
89
+ if (!uid) {
90
+ if (debug) console.error("[UIX] no uid found in init params or extension URL");
91
+ return reject({
92
+ error: 'missing_uid',
93
+ message: 'Missing UID: no UID found in init params or extension URL'
94
+ });
95
+ }
96
+ if (debug) console.info("[UIX:" + uid + "] initializing with uid " + uid);
97
+ zoid.create({
98
+ tag: uid,
99
+ url: window.location.href.toString(),
100
+ autoResize: {
101
+ width: false,
102
+ height: true,
103
+ element: 'html'
104
+ },
105
+ props: {
106
+ onConnected: {
107
+ type: 'function'
108
+ }
109
+ }
110
+ });
111
+ if (typeof window.xprops !== 'undefined') {
112
+ var _window$xprops = window.xprops,
113
+ onConnected = _window$xprops.onConnected;
114
+ onConnected(uid).then(function (status) {
115
+ if (status === true) {
116
+ var _window$xprops2 = window.xprops,
117
+ onParentProps = _window$xprops2.onProps,
118
+ resize = _window$xprops2.resize,
119
+ extensionProps = _objectWithoutPropertiesLoose(_window$xprops2, _excluded);
120
+ if (debug) console.info("[UIX:" + uid + "] initial shared props", extensionProps);
121
+ onParentProps(function (p) {
122
+ var newExtensionProps = _objectWithoutPropertiesLoose(p, _excluded2);
123
+ if (debug) console.info("[UIX:" + uid + "] new shared props", newExtensionProps);
124
+ if ('isExpanded' in p && typeof p.isExpanded === 'boolean') {
125
+ p.isExpanded ? resize({
126
+ height: 'full',
127
+ width: '100%'
128
+ }) : resize({
129
+ height: 'auto',
130
+ width: '100%'
131
+ });
132
+ }
133
+ onProps(handleProps(newExtensionProps));
134
+ });
135
+ if (debug) console.info("[UIX:" + uid + "] initialized");
136
+ onProps(handleProps(extensionProps));
137
+ resolve({
138
+ status: 'ok',
139
+ props: handleProps(extensionProps)
140
+ });
141
+ } else {
142
+ if (debug) console.info("[UIX:" + uid + "] sdk renderer returned status:", status);
143
+ resolve({
144
+ status: 'validation'
145
+ });
146
+ }
147
+ });
148
+ } else {
149
+ if (debug) console.error("[UIX] no shared props from host found");
150
+ reject({
151
+ error: 'failed_communication',
152
+ message: 'No communication established with host, please check your URL'
153
+ });
154
+ }
155
+ });
156
+ }
157
+ var index = {
158
+ init: init
159
+ };
160
+
161
+ exports.AppInstallationStatus = AppInstallationStatus;
162
+ exports.FieldExtensionFeature = FieldExtensionFeature;
163
+ exports.FieldExtensionType = FieldExtensionType;
164
+ exports.default = index;
165
+ exports.init = init;
166
+ exports.reservedExtensionProps = reservedExtensionProps;
167
+ //# sourceMappingURL=app-sdk.cjs.development.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-sdk.cjs.development.js","sources":["../src/base.ts","../src/field.ts","../src/type-helpers/appInstallation.ts","../src/index.ts"],"sourcesContent":["import type { ShowToast } from './type-helpers/toast';\nimport type { OpenDialog } from './type-helpers/dialog';\nimport type { OpenAssetPicker } from './type-helpers/openAssetPicker';\n\n// see https://github.com/krakenjs/zoid/blob/master/src/component/props.js#L53\nexport const reservedExtensionProps = [\n 'timeout',\n 'window',\n 'close',\n 'focus',\n 'resize',\n 'uid',\n 'cspNonce',\n 'getParent',\n 'getParentDomain',\n 'hide',\n 'show',\n 'export',\n 'onDisplay',\n 'onRendered',\n 'onRender',\n 'onClose',\n 'onDestroy',\n 'onResize',\n 'onFocus',\n 'onError',\n 'onProps',\n];\n\nexport enum ExtensionPermission {\n INPUT = 'INPUT',\n FORM = 'FORM',\n API = 'API',\n}\n\ntype ConfigVariableName = string;\n\ntype ConfigVariableSettings = {\n type: 'string' | 'number' | 'boolean';\n displayName?: string;\n description?: string;\n required?: boolean;\n defaultValue?: any;\n};\n\nexport type ConfigFields = Record<ConfigVariableName, ConfigVariableSettings>;\n\nexport type ConfigValue = Record<\n string,\n boolean | number | string | undefined | null\n>;\n\nexport type FieldConfig = {\n tableConfig: ConfigValue;\n fieldConfig: ConfigValue;\n};\n\nexport type FormSidebarConfig = { sidebarConfig: ConfigValue };\n\nexport type Project = {\n id: string;\n name: string;\n mgmtApi: string;\n mgmtToken: string;\n};\n\nexport type Environment = {\n id: string;\n name: string;\n endpoint: string;\n authToken: string;\n};\n\nexport type Context = {\n project: Project;\n environment: Environment;\n};\n\nexport interface ExtensionPropsBase {\n context: Context;\n openDialog: OpenDialog;\n showToast: ShowToast;\n openAssetPicker: OpenAssetPicker;\n redirectParent: (location: string | Location) => Promise<void>;\n historyReplace: (url: string | HistoryCallback) => Promise<void>;\n historyPush: (url: string | HistoryCallback) => Promise<void>;\n}\n\nexport interface ExtensionDialogProps extends ExtensionPropsBase {\n onCloseDialog: (value: any) => void;\n}\n\ntype HistoryCallback = (href: Location['href']) => string;\n","import type { Form } from './type-helpers/form';\nimport type { ExtensionPropsBase, ConfigValue } from './base';\nimport type { Model } from './type-helpers/model';\nimport type { AppInstallation } from './type-helpers/appInstallation';\nimport type { Field } from './type-helpers/field';\n\nexport const FieldExtensionType = {\n STRING: 'STRING',\n RICHTEXT: 'RICHTEXT',\n INT: 'INT',\n FLOAT: 'FLOAT',\n BOOLEAN: 'BOOLEAN',\n JSON: 'JSON',\n DATETIME: 'DATETIME',\n DATE: 'DATE',\n LOCATION: 'LOCATION',\n COLOR: 'COLOR',\n ENUMERATION: 'ENUMERATION',\n RELATION: 'RELATION',\n ASSET: 'ASSET',\n UNION: 'UNION',\n} as const;\n\nexport const FieldExtensionFeature = {\n FieldRenderer: 'FieldRenderer',\n ListRenderer: 'ListRenderer',\n TableRenderer: 'TableRenderer',\n} as const;\n\nexport interface FieldExtensionProps extends ExtensionPropsBase {\n extension: {\n config: ConfigValue;\n tableConfig: ConfigValue;\n fieldConfig: ConfigValue;\n id: string;\n };\n\n isExpanded: boolean;\n expand: (expand: boolean | ((isExpanded: boolean) => boolean)) => unknown;\n\n // name of the field in the form (may differ from the field apiId, ie. for localized fields)\n name: string;\n\n // current locale on localized field\n locale: string | undefined;\n\n // current entry id, null for new entries;\n entryId: string | null;\n\n isTableCell: boolean;\n\n isReadOnly: boolean | undefined;\n\n value: any;\n\n onBlur: (event?: FocusEvent) => Promise<void>;\n\n onChange: (event: InputEvent | any) => Promise<void>;\n\n onFocus: (event?: FocusEvent) => Promise<void>;\n\n // @see https://final-form.org/docs/react-final-form/types/FieldRenderProps\n meta: {\n active: boolean;\n error: any;\n touched: boolean;\n };\n\n form: Form;\n field: Field;\n model: Model;\n installation: AppInstallation;\n}\n","import type { ConfigValue } from '../base';\n\nexport const AppInstallationStatus = {\n COMPLETED: 'COMPLETED',\n DISABLED: 'DISABLED',\n PENDING: 'PENDING',\n} as const;\n\nexport type AppInstallation = {\n id: string;\n config: ConfigValue;\n status: keyof typeof AppInstallationStatus;\n};\n","import zoid from '@graphcms/zoid/lib/zoid.js';\n\nimport { ExtensionDialogProps, reservedExtensionProps } from './base';\nexport { ExtensionDialogProps, reservedExtensionProps } from './base';\nimport type { FieldExtensionProps } from './field';\nimport type { FormSidebarExtensionProps } from './formSidebar';\nexport * from './base';\nexport type {\n FormState,\n FieldState,\n FieldSubscription,\n Subscriber,\n FormSubscription,\n Form,\n} from './type-helpers/form';\n\nexport type {\n VisibilityTypes,\n SetFieldsVisibility,\n VisibilityMap,\n} from './type-helpers/visibility';\n\nexport type { FieldExtensionProps } from './field';\nexport type { AppProps } from './app';\nexport type { FormSidebarExtensionProps } from './formSidebar';\nexport { FieldExtensionFeature, FieldExtensionType } from './field';\nexport * from './type-helpers/appInstallation';\n\nexport type ExtensionProps =\n | FieldExtensionProps\n | FormSidebarExtensionProps\n | ExtensionDialogProps;\n\ntype Xprops = {\n onProps: (props: Record<string, any>) => void;\n onConnected: (uid: string) => Promise<unknown>;\n resize: (size: {\n height: 'auto' | 'full' | number;\n width: 'auto' | '100%' | number;\n }) => unknown;\n} & ExtensionProps;\n\ndeclare global {\n interface Window {\n xprops: Xprops;\n }\n}\n\nfunction handleProps(props: any) {\n const transformedProps: any = {};\n Object.keys(props).forEach((key: string) => {\n // do not pass down zoid props to the extension\n if (reservedExtensionProps.includes(key)) return;\n\n // transform props that were prefixed with '_' to bypass zoid reverved props\n if (\n key.startsWith('_') &&\n reservedExtensionProps.includes(key.replace(/^_/g, ''))\n ) {\n transformedProps[key.replace(/^_/g, '')] = props[key];\n } else {\n transformedProps[key] = props[key];\n }\n });\n return transformedProps;\n}\n\nexport function init({\n debug,\n onProps = () => undefined,\n uid: givenUid,\n}: {\n onProps: (props: any) => unknown;\n debug?: boolean;\n uid?: string;\n}) {\n return new Promise<{ status: 'ok'; props: any } | { status: 'validation' }>(\n (resolve, reject) => {\n if (\n typeof window === 'undefined' ||\n typeof window.postMessage === 'undefined'\n ) {\n return reject({\n error: 'unsupported_env',\n message:\n 'Unsupported environment: Not in a browser supporting PostMessage',\n });\n }\n\n const uid =\n givenUid ||\n (typeof URLSearchParams !== 'undefined' &&\n new URLSearchParams(window.location.search).get('extensionUid'));\n\n if (!uid) {\n if (debug)\n console.error(`[UIX] no uid found in init params or extension URL`);\n return reject({\n error: 'missing_uid',\n message: 'Missing UID: no UID found in init params or extension URL',\n });\n }\n if (debug) console.info(`[UIX:${uid}] initializing with uid ${uid}`);\n\n zoid.create({\n tag: uid,\n url: window.location.href.toString(),\n autoResize: {\n width: false,\n height: true,\n element: 'html',\n },\n props: {\n onConnected: {\n type: 'function',\n },\n },\n });\n if (typeof window.xprops !== 'undefined') {\n const { onConnected, onProps: initialOnProps } = window.xprops;\n\n onConnected(uid).then((status) => {\n if (status === true) {\n const {\n onProps: onParentProps,\n onConnected: _nevermind,\n resize,\n ...extensionProps\n } = window.xprops;\n\n if (debug)\n console.info(`[UIX:${uid}] initial shared props`, extensionProps);\n onParentProps((p: Xprops) => {\n const {\n onProps: onParentProps,\n onConnected,\n ...newExtensionProps\n } = p;\n\n if (debug)\n console.info(\n `[UIX:${uid}] new shared props`,\n newExtensionProps\n );\n if ('isExpanded' in p && typeof p.isExpanded === 'boolean') {\n p.isExpanded\n ? resize({ height: 'full', width: '100%' })\n : resize({ height: 'auto', width: '100%' });\n }\n onProps(handleProps(newExtensionProps));\n });\n\n if (debug) console.info(`[UIX:${uid}] initialized`);\n onProps(handleProps(extensionProps));\n resolve({ status: 'ok', props: handleProps(extensionProps) });\n } else {\n if (debug)\n console.info(\n `[UIX:${uid}] sdk renderer returned status:`,\n status\n );\n resolve({ status: 'validation' });\n }\n });\n } else {\n if (debug) console.error(`[UIX] no shared props from host found`);\n reject({\n error: 'failed_communication',\n message:\n 'No communication established with host, please check your URL',\n });\n }\n }\n );\n}\n\nexport default { init };\n"],"names":["reservedExtensionProps","ExtensionPermission","FieldExtensionType","STRING","RICHTEXT","INT","FLOAT","BOOLEAN","JSON","DATETIME","DATE","LOCATION","COLOR","ENUMERATION","RELATION","ASSET","UNION","FieldExtensionFeature","FieldRenderer","ListRenderer","TableRenderer","AppInstallationStatus","COMPLETED","DISABLED","PENDING","handleProps","props","transformedProps","Object","keys","forEach","key","includes","startsWith","replace","init","debug","onProps","undefined","givenUid","uid","Promise","resolve","reject","window","postMessage","error","message","URLSearchParams","location","search","get","console","info","zoid","create","tag","url","href","toString","autoResize","width","height","element","onConnected","type","xprops","then","status","onParentProps","_nevermind","resize","extensionProps","p","newExtensionProps","isExpanded"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAIA;IACaA,sBAAsB,GAAG,CACpC,SAAS,EACT,QAAQ,EACR,OAAO,EACP,OAAO,EACP,QAAQ,EACR,KAAK,EACL,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,MAAM,EACN,MAAM,EACN,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,UAAU,EACV,SAAS,EACT,WAAW,EACX,UAAU,EACV,SAAS,EACT,SAAS,EACT,SAAS;AAGX,WAAYC,mBAAmB;EAC7BA,sCAAe;EACfA,oCAAa;EACbA,kCAAW;AACb,CAAC,EAJWA,2BAAmB,KAAnBA,2BAAmB;;ICvBlBC,kBAAkB,GAAG;EAChCC,MAAM,EAAE,QAAQ;EAChBC,QAAQ,EAAE,UAAU;EACpBC,GAAG,EAAE,KAAK;EACVC,KAAK,EAAE,OAAO;EACdC,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AI,WAASb,GAAG,6BAA0BgC,cAAc,CAAC;UACnEH,aAAa,CAAC,UAACI,CAAS;YACtB,IAGKC,iBAAiB,iCAClBD,CAAC;YAEL,IAAIrC,KAAK,EACPgB,OAAO,CAACC,IAAI,WACFb,GAAG,yBACXkC,iBAAiB,CAClB;YACH,IAAI,YAAY,IAAID,CAAC,IAAI,OAAOA,CAAC,CAACE,UAAU,KAAK,SAAS,EAAE;cAC1DF,CAAC,CAACE,UAAU,GACRJ,MAAM,CAAC;gBAAET,MAAM,EAAE,MAAM;gBAAED,KAAK,EAAE;eAAQ,CAAC,GACzCU,MAAM,CAAC;gBAAET,MAAM,EAAE,MAAM;gBAAED,KAAK,EAAE;eAAQ,CAAC;;YAE/CxB,OAAO,CAACZ,WAAW,CAACiD,iBAAiB,CAAC,CAAC;WACxC,CAAC;UAEF,IAAItC,KAAK,EAAEgB,OAAO,CAACC,IAAI,WAASb,GAAG,mBAAgB;UACnDH,OAAO,CAACZ,WAAW,CAAC+C,cAAc,CAAC,CAAC;UACpC9B,OAAO,CAAC;YAAE0B,MAAM,EAAE,IAAI;YAAE1C,KAAK,EAAED,WAAW,CAAC+C,cAAc;WAAG,CAAC;SAC9D,MAAM;UACL,IAAIpC,KAAK,EACPgB,OAAO,CAACC,IAAI,WACFb,GAAG,sCACX4B,MAAM,CACP;UACH1B,OAAO,CAAC;YAAE0B,MAAM,EAAE;WAAc,CAAC;;OAEpC,CAAC;KACH,MAAM;MACL,IAAIhC,KAAK,EAAEgB,OAAO,CAACN,KAAK,yCAAyC;MACjEH,MAAM,CAAC;QACLG,KAAK,EAAE,sBAAsB;QAC7BC,OAAO,EACL;OACH,CAAC;;GAEL,CACF;AACH;AAEA,YAAe;EAAEZ,IAAI,EAAJA;CAAM;;;;;;;;;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,n=(e=require("@graphcms/zoid/lib/zoid.js"))&&"object"==typeof e&&"default"in e?e.default:e;function o(e,n){if(null==e)return{};var o,r,i={},t=Object.keys(e);for(r=0;r<t.length;r++)n.indexOf(o=t[r])>=0||(i[o]=e[o]);return i}var r,i=["timeout","window","close","focus","resize","uid","cspNonce","getParent","getParentDomain","hide","show","export","onDisplay","onRendered","onRender","onClose","onDestroy","onResize","onFocus","onError","onProps"];(r=exports.ExtensionPermission||(exports.ExtensionPermission={})).INPUT="INPUT",r.FORM="FORM",r.API="API";var t=["onProps","onConnected","resize"],s=["onProps","onConnected"];function d(e){var n={};return Object.keys(e).forEach((function(o){i.includes(o)||(o.startsWith("_")&&i.includes(o.replace(/^_/g,""))?n[o.replace(/^_/g,"")]=e[o]:n[o]=e[o])})),n}function a(e){var r=e.debug,i=e.onProps,a=void 0===i?function(){}:i,p=e.uid;return new Promise((function(e,i){if("undefined"==typeof window||void 0===window.postMessage)return i({error:"unsupported_env",message:"Unsupported environment: Not in a browser supporting PostMessage"});var u=p||"undefined"!=typeof URLSearchParams&&new URLSearchParams(window.location.search).get("extensionUid");if(!u)return r&&console.error("[UIX] no uid found in init params or extension URL"),i({error:"missing_uid",message:"Missing UID: no UID found in init params or extension URL"});r&&console.info("[UIX:"+u+"] initializing with uid "+u),n.create({tag:u,url:window.location.href.toString(),autoResize:{width:!1,height:!0,element:"html"},props:{onConnected:{type:"function"}}}),void 0!==window.xprops?(0,window.xprops.onConnected)(u).then((function(n){if(!0===n){var i=window.xprops,p=i.onProps,c=i.resize,l=o(i,t);r&&console.info("[UIX:"+u+"] initial shared props",l),p((function(e){var n=o(e,s);r&&console.info("[UIX:"+u+"] new shared props",n),"isExpanded"in e&&"boolean"==typeof e.isExpanded&&c(e.isExpanded?{height:"full",width:"100%"}:{height:"auto",width:"100%"}),a(d(n))})),r&&console.info("[UIX:"+u+"] initialized"),a(d(l)),e({status:"ok",props:d(l)})}else r&&console.info("[UIX:"+u+"] sdk renderer returned status:",n),e({status:"validation"})})):(r&&console.error("[UIX] no shared props from host found"),i({error:"failed_communication",message:"No communication established with host, please check your URL"}))}))}var p={init:a};exports.AppInstallationStatus={COMPLETED:"COMPLETED",DISABLED:"DISABLED",PENDING:"PENDING"},exports.FieldExtensionFeature={FieldRenderer:"FieldRenderer",ListRenderer:"ListRenderer",TableRenderer:"TableRenderer"},exports.FieldExtensionType={STRING:"STRING",RICHTEXT:"RICHTEXT",INT:"INT",FLOAT:"FLOAT",BOOLEAN:"BOOLEAN",JSON:"JSON",DATETIME:"DATETIME",DATE:"DATE",LOCATION:"LOCATION",COLOR:"COLOR",ENUMERATION:"ENUMERATION",RELATION:"RELATION",ASSET:"ASSET",UNION:"UNION"},exports.default=p,exports.init=a,exports.reservedExtensionProps=i;
2
+ //# sourceMappingURL=app-sdk.cjs.production.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-sdk.cjs.production.min.js","sources":["../src/base.ts","../src/index.ts","../src/type-helpers/appInstallation.ts","../src/field.ts"],"sourcesContent":["import type { ShowToast } from './type-helpers/toast';\nimport type { OpenDialog } from './type-helpers/dialog';\nimport type { OpenAssetPicker } from './type-helpers/openAssetPicker';\n\n// see https://github.com/krakenjs/zoid/blob/master/src/component/props.js#L53\nexport const reservedExtensionProps = [\n 'timeout',\n 'window',\n 'close',\n 'focus',\n 'resize',\n 'uid',\n 'cspNonce',\n 'getParent',\n 'getParentDomain',\n 'hide',\n 'show',\n 'export',\n 'onDisplay',\n 'onRendered',\n 'onRender',\n 'onClose',\n 'onDestroy',\n 'onResize',\n 'onFocus',\n 'onError',\n 'onProps',\n];\n\nexport enum ExtensionPermission {\n INPUT = 'INPUT',\n FORM = 'FORM',\n API = 'API',\n}\n\ntype ConfigVariableName = string;\n\ntype ConfigVariableSettings = {\n type: 'string' | 'number' | 'boolean';\n displayName?: string;\n description?: string;\n required?: boolean;\n defaultValue?: any;\n};\n\nexport type ConfigFields = Record<ConfigVariableName, ConfigVariableSettings>;\n\nexport type ConfigValue = Record<\n string,\n boolean | number | string | undefined | null\n>;\n\nexport type FieldConfig = {\n tableConfig: ConfigValue;\n fieldConfig: ConfigValue;\n};\n\nexport type FormSidebarConfig = { sidebarConfig: ConfigValue };\n\nexport type Project = {\n id: string;\n name: string;\n mgmtApi: string;\n mgmtToken: string;\n};\n\nexport type Environment = {\n id: string;\n name: string;\n endpoint: string;\n authToken: string;\n};\n\nexport type Context = {\n project: Project;\n environment: Environment;\n};\n\nexport interface ExtensionPropsBase {\n context: Context;\n openDialog: OpenDialog;\n showToast: ShowToast;\n openAssetPicker: OpenAssetPicker;\n redirectParent: (location: string | Location) => Promise<void>;\n historyReplace: (url: string | HistoryCallback) => Promise<void>;\n historyPush: (url: string | HistoryCallback) => Promise<void>;\n}\n\nexport interface ExtensionDialogProps extends ExtensionPropsBase {\n onCloseDialog: (value: any) => void;\n}\n\ntype HistoryCallback = (href: Location['href']) => string;\n","import zoid from '@graphcms/zoid/lib/zoid.js';\n\nimport { ExtensionDialogProps, reservedExtensionProps } from './base';\nexport { ExtensionDialogProps, reservedExtensionProps } from './base';\nimport type { FieldExtensionProps } from './field';\nimport type { FormSidebarExtensionProps } from './formSidebar';\nexport * from './base';\nexport type {\n FormState,\n FieldState,\n FieldSubscription,\n Subscriber,\n FormSubscription,\n Form,\n} from './type-helpers/form';\n\nexport type {\n VisibilityTypes,\n SetFieldsVisibility,\n VisibilityMap,\n} from './type-helpers/visibility';\n\nexport type { FieldExtensionProps } from './field';\nexport type { AppProps } from './app';\nexport type { FormSidebarExtensionProps } from './formSidebar';\nexport { FieldExtensionFeature, FieldExtensionType } from './field';\nexport * from './type-helpers/appInstallation';\n\nexport type ExtensionProps =\n | FieldExtensionProps\n | FormSidebarExtensionProps\n | ExtensionDialogProps;\n\ntype Xprops = {\n onProps: (props: Record<string, any>) => void;\n onConnected: (uid: string) => Promise<unknown>;\n resize: (size: {\n height: 'auto' | 'full' | number;\n width: 'auto' | '100%' | number;\n }) => unknown;\n} & ExtensionProps;\n\ndeclare global {\n interface Window {\n xprops: Xprops;\n }\n}\n\nfunction handleProps(props: any) {\n const transformedProps: any = {};\n Object.keys(props).forEach((key: string) => {\n // do not pass down zoid props to the extension\n if (reservedExtensionProps.includes(key)) return;\n\n // transform props that were prefixed with '_' to bypass zoid reverved props\n if (\n key.startsWith('_') &&\n reservedExtensionProps.includes(key.replace(/^_/g, ''))\n ) {\n transformedProps[key.replace(/^_/g, '')] = props[key];\n } else {\n transformedProps[key] = props[key];\n }\n });\n return transformedProps;\n}\n\nexport function init({\n debug,\n onProps = () => undefined,\n uid: givenUid,\n}: {\n onProps: (props: any) => unknown;\n debug?: boolean;\n uid?: string;\n}) {\n return new Promise<{ status: 'ok'; props: any } | { status: 'validation' }>(\n (resolve, reject) => {\n if (\n typeof window === 'undefined' ||\n typeof window.postMessage === 'undefined'\n ) {\n return reject({\n error: 'unsupported_env',\n message:\n 'Unsupported environment: Not in a browser supporting PostMessage',\n });\n }\n\n const uid =\n givenUid ||\n (typeof URLSearchParams !== 'undefined' &&\n new URLSearchParams(window.location.search).get('extensionUid'));\n\n if (!uid) {\n if (debug)\n console.error(`[UIX] no uid found in init params or extension URL`);\n return reject({\n error: 'missing_uid',\n message: 'Missing UID: no UID found in init params or extension URL',\n });\n }\n if (debug) console.info(`[UIX:${uid}] initializing with uid ${uid}`);\n\n zoid.create({\n tag: uid,\n url: window.location.href.toString(),\n autoResize: {\n width: false,\n height: true,\n element: 'html',\n },\n props: {\n onConnected: {\n type: 'function',\n },\n },\n });\n if (typeof window.xprops !== 'undefined') {\n const { onConnected, onProps: initialOnProps } = window.xprops;\n\n onConnected(uid).then((status) => {\n if (status === true) {\n const {\n onProps: onParentProps,\n onConnected: _nevermind,\n resize,\n ...extensionProps\n } = window.xprops;\n\n if (debug)\n console.info(`[UIX:${uid}] initial shared props`, extensionProps);\n onParentProps((p: Xprops) => {\n const {\n onProps: onParentProps,\n onConnected,\n ...newExtensionProps\n } = p;\n\n if (debug)\n console.info(\n `[UIX:${uid}] new shared props`,\n newExtensionProps\n );\n if ('isExpanded' in p && typeof p.isExpanded === 'boolean') {\n p.isExpanded\n ? resize({ height: 'full', width: '100%' })\n : resize({ height: 'auto', width: '100%' });\n }\n onProps(handleProps(newExtensionProps));\n });\n\n if (debug) console.info(`[UIX:${uid}] initialized`);\n onProps(handleProps(extensionProps));\n resolve({ status: 'ok', props: handleProps(extensionProps) });\n } else {\n if (debug)\n console.info(\n `[UIX:${uid}] sdk renderer returned status:`,\n status\n );\n resolve({ status: 'validation' });\n }\n });\n } else {\n if (debug) console.error(`[UIX] no shared props from host found`);\n reject({\n error: 'failed_communication',\n message:\n 'No communication established with host, please check your URL',\n });\n }\n }\n );\n}\n\nexport default { init };\n","import type { ConfigValue } from '../base';\n\nexport const AppInstallationStatus = {\n COMPLETED: 'COMPLETED',\n DISABLED: 'DISABLED',\n PENDING: 'PENDING',\n} as const;\n\nexport type AppInstallation = {\n id: string;\n config: ConfigValue;\n status: keyof typeof AppInstallationStatus;\n};\n","import type { Form } from './type-helpers/form';\nimport type { ExtensionPropsBase, ConfigValue } from './base';\nimport type { Model } from './type-helpers/model';\nimport type { AppInstallation } from './type-helpers/appInstallation';\nimport type { Field } from './type-helpers/field';\n\nexport const FieldExtensionType = {\n STRING: 'STRING',\n RICHTEXT: 'RICHTEXT',\n INT: 'INT',\n FLOAT: 'FLOAT',\n BOOLEAN: 'BOOLEAN',\n JSON: 'JSON',\n DATETIME: 'DATETIME',\n DATE: 'DATE',\n LOCATION: 'LOCATION',\n COLOR: 'COLOR',\n ENUMERATION: 'ENUMERATION',\n RELATION: 'RELATION',\n ASSET: 'ASSET',\n UNION: 'UNION',\n} as const;\n\nexport const FieldExtensionFeature = {\n FieldRenderer: 'FieldRenderer',\n ListRenderer: 'ListRenderer',\n TableRenderer: 'TableRenderer',\n} as const;\n\nexport interface FieldExtensionProps extends ExtensionPropsBase {\n extension: {\n config: ConfigValue;\n tableConfig: ConfigValue;\n fieldConfig: ConfigValue;\n id: string;\n };\n\n isExpanded: boolean;\n expand: (expand: boolean | ((isExpanded: boolean) => boolean)) => unknown;\n\n // name of the field in the form (may differ from the field apiId, ie. for localized fields)\n name: string;\n\n // current locale on localized field\n locale: string | undefined;\n\n // current entry id, null for new entries;\n entryId: string | null;\n\n isTableCell: boolean;\n\n isReadOnly: boolean | undefined;\n\n value: any;\n\n onBlur: (event?: FocusEvent) => Promise<void>;\n\n onChange: (event: InputEvent | any) => Promise<void>;\n\n onFocus: (event?: FocusEvent) => Promise<void>;\n\n // @see https://final-form.org/docs/react-final-form/types/FieldRenderProps\n meta: {\n active: boolean;\n error: any;\n touched: boolean;\n };\n\n form: Form;\n field: Field;\n model: Model;\n installation: AppInstallation;\n}\n"],"names":["ExtensionPermission","reservedExtensionProps","handleProps","props","transformedProps","Object","keys","forEach","key","includes","startsWith","replace","init","debug","_ref$onProps","onProps","givenUid","uid","Promise","resolve","reject","window","postMessage","error","message","URLSearchParams","location","search","get","console","info","zoid","create","tag","url","href","toString","autoResize","width","height","element","onConnected","type","xprops","then","status","onParentProps","_nevermind","resize","extensionProps","p","newExtensionProps","isExpanded","COMPLETED","DISABLED","PENDING","FieldRenderer","ListRenderer","TableRenderer","STRING","RICHTEXT","INT","FLOAT","BOOLEAN","JSON","DATETIME","DATE","LOCATION","COLOR","ENUMERATION","RELATION","ASSET","UNION"],"mappings":"6SA6BYA,EAxBCC,EAAyB,CACpC,UACA,SACA,QACA,QACA,SACA,MACA,WACA,YACA,kBACA,OACA,OACA,SACA,YACA,aACA,WACA,UACA,YACA,WACA,UACA,UACA,YAGUD,EAAAA,8BAAAA,+CAEVA,cACAA,iFCgBF,SAASE,EAAYC,GACnB,IAAMC,EAAwB,GAe9B,OAdAC,OAAOC,KAAKH,GAAOI,SAAQ,SAACC,GAEtBP,EAAuBQ,SAASD,KAIlCA,EAAIE,WAAW,MACfT,EAAuBQ,SAASD,EAAIG,QAAQ,MAAO,KAEnDP,EAAiBI,EAAIG,QAAQ,MAAO,KAAOR,EAAMK,GAEjDJ,EAAiBI,GAAOL,EAAMK,OAG3BJ,WAGOQ,SACdC,IAAAA,MAAKC,IACLC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C9KoB,CACnCyC,UAAW,YACXC,SAAU,WACVC,QAAS,yCCkB0B,CACnCC,cAAe,gBACfC,aAAc,eACdC,cAAe,4CApBiB,CAChCC,OAAQ,SACRC,SAAU,WACVC,IAAK,MACLC,MAAO,QACPC,QAAS,UACTC,KAAM,OACNC,SAAU,WACVC,KAAM,OACNC,SAAU,WACVC,MAAO,QACPC,YAAa,cACbC,SAAU,WACVC,MAAO,QACPC,MAAO"}
@@ -0,0 +1,158 @@
1
+ import zoid from '@graphcms/zoid/lib/zoid.js';
2
+
3
+ function _objectWithoutPropertiesLoose(source, excluded) {
4
+ if (source == null) return {};
5
+ var target = {};
6
+ var sourceKeys = Object.keys(source);
7
+ var key, i;
8
+ for (i = 0; i < sourceKeys.length; i++) {
9
+ key = sourceKeys[i];
10
+ if (excluded.indexOf(key) >= 0) continue;
11
+ target[key] = source[key];
12
+ }
13
+ return target;
14
+ }
15
+
16
+ // see https://github.com/krakenjs/zoid/blob/master/src/component/props.js#L53
17
+ var reservedExtensionProps = ['timeout', 'window', 'close', 'focus', 'resize', 'uid', 'cspNonce', 'getParent', 'getParentDomain', 'hide', 'show', 'export', 'onDisplay', 'onRendered', 'onRender', 'onClose', 'onDestroy', 'onResize', 'onFocus', 'onError', 'onProps'];
18
+ var ExtensionPermission;
19
+ (function (ExtensionPermission) {
20
+ ExtensionPermission["INPUT"] = "INPUT";
21
+ ExtensionPermission["FORM"] = "FORM";
22
+ ExtensionPermission["API"] = "API";
23
+ })(ExtensionPermission || (ExtensionPermission = {}));
24
+
25
+ var FieldExtensionType = {
26
+ STRING: 'STRING',
27
+ RICHTEXT: 'RICHTEXT',
28
+ INT: 'INT',
29
+ FLOAT: 'FLOAT',
30
+ BOOLEAN: 'BOOLEAN',
31
+ JSON: 'JSON',
32
+ DATETIME: 'DATETIME',
33
+ DATE: 'DATE',
34
+ LOCATION: 'LOCATION',
35
+ COLOR: 'COLOR',
36
+ ENUMERATION: 'ENUMERATION',
37
+ RELATION: 'RELATION',
38
+ ASSET: 'ASSET',
39
+ UNION: 'UNION'
40
+ };
41
+ var FieldExtensionFeature = {
42
+ FieldRenderer: 'FieldRenderer',
43
+ ListRenderer: 'ListRenderer',
44
+ TableRenderer: 'TableRenderer'
45
+ };
46
+
47
+ var AppInstallationStatus = {
48
+ COMPLETED: 'COMPLETED',
49
+ DISABLED: 'DISABLED',
50
+ PENDING: 'PENDING'
51
+ };
52
+
53
+ var _excluded = ["onProps", "onConnected", "resize"],
54
+ _excluded2 = ["onProps", "onConnected"];
55
+ function handleProps(props) {
56
+ var transformedProps = {};
57
+ Object.keys(props).forEach(function (key) {
58
+ // do not pass down zoid props to the extension
59
+ if (reservedExtensionProps.includes(key)) return;
60
+ // transform props that were prefixed with '_' to bypass zoid reverved props
61
+ if (key.startsWith('_') && reservedExtensionProps.includes(key.replace(/^_/g, ''))) {
62
+ transformedProps[key.replace(/^_/g, '')] = props[key];
63
+ } else {
64
+ transformedProps[key] = props[key];
65
+ }
66
+ });
67
+ return transformedProps;
68
+ }
69
+ function init(_ref) {
70
+ var debug = _ref.debug,
71
+ _ref$onProps = _ref.onProps,
72
+ onProps = _ref$onProps === void 0 ? function () {
73
+ return undefined;
74
+ } : _ref$onProps,
75
+ givenUid = _ref.uid;
76
+ return new Promise(function (resolve, reject) {
77
+ if (typeof window === 'undefined' || typeof window.postMessage === 'undefined') {
78
+ return reject({
79
+ error: 'unsupported_env',
80
+ message: 'Unsupported environment: Not in a browser supporting PostMessage'
81
+ });
82
+ }
83
+ var uid = givenUid || typeof URLSearchParams !== 'undefined' && new URLSearchParams(window.location.search).get('extensionUid');
84
+ if (!uid) {
85
+ if (debug) console.error("[UIX] no uid found in init params or extension URL");
86
+ return reject({
87
+ error: 'missing_uid',
88
+ message: 'Missing UID: no UID found in init params or extension URL'
89
+ });
90
+ }
91
+ if (debug) console.info("[UIX:" + uid + "] initializing with uid " + uid);
92
+ zoid.create({
93
+ tag: uid,
94
+ url: window.location.href.toString(),
95
+ autoResize: {
96
+ width: false,
97
+ height: true,
98
+ element: 'html'
99
+ },
100
+ props: {
101
+ onConnected: {
102
+ type: 'function'
103
+ }
104
+ }
105
+ });
106
+ if (typeof window.xprops !== 'undefined') {
107
+ var _window$xprops = window.xprops,
108
+ onConnected = _window$xprops.onConnected;
109
+ onConnected(uid).then(function (status) {
110
+ if (status === true) {
111
+ var _window$xprops2 = window.xprops,
112
+ onParentProps = _window$xprops2.onProps,
113
+ resize = _window$xprops2.resize,
114
+ extensionProps = _objectWithoutPropertiesLoose(_window$xprops2, _excluded);
115
+ if (debug) console.info("[UIX:" + uid + "] initial shared props", extensionProps);
116
+ onParentProps(function (p) {
117
+ var newExtensionProps = _objectWithoutPropertiesLoose(p, _excluded2);
118
+ if (debug) console.info("[UIX:" + uid + "] new shared props", newExtensionProps);
119
+ if ('isExpanded' in p && typeof p.isExpanded === 'boolean') {
120
+ p.isExpanded ? resize({
121
+ height: 'full',
122
+ width: '100%'
123
+ }) : resize({
124
+ height: 'auto',
125
+ width: '100%'
126
+ });
127
+ }
128
+ onProps(handleProps(newExtensionProps));
129
+ });
130
+ if (debug) console.info("[UIX:" + uid + "] initialized");
131
+ onProps(handleProps(extensionProps));
132
+ resolve({
133
+ status: 'ok',
134
+ props: handleProps(extensionProps)
135
+ });
136
+ } else {
137
+ if (debug) console.info("[UIX:" + uid + "] sdk renderer returned status:", status);
138
+ resolve({
139
+ status: 'validation'
140
+ });
141
+ }
142
+ });
143
+ } else {
144
+ if (debug) console.error("[UIX] no shared props from host found");
145
+ reject({
146
+ error: 'failed_communication',
147
+ message: 'No communication established with host, please check your URL'
148
+ });
149
+ }
150
+ });
151
+ }
152
+ var index = {
153
+ init: init
154
+ };
155
+
156
+ export default index;
157
+ export { AppInstallationStatus, ExtensionPermission, FieldExtensionFeature, FieldExtensionType, init, reservedExtensionProps };
158
+ //# sourceMappingURL=app-sdk.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-sdk.esm.js","sources":["../src/base.ts","../src/field.ts","../src/type-helpers/appInstallation.ts","../src/index.ts"],"sourcesContent":["import type { ShowToast } from './type-helpers/toast';\nimport type { OpenDialog } from './type-helpers/dialog';\nimport type { OpenAssetPicker } from './type-helpers/openAssetPicker';\n\n// see https://github.com/krakenjs/zoid/blob/master/src/component/props.js#L53\nexport const reservedExtensionProps = [\n 'timeout',\n 'window',\n 'close',\n 'focus',\n 'resize',\n 'uid',\n 'cspNonce',\n 'getParent',\n 'getParentDomain',\n 'hide',\n 'show',\n 'export',\n 'onDisplay',\n 'onRendered',\n 'onRender',\n 'onClose',\n 'onDestroy',\n 'onResize',\n 'onFocus',\n 'onError',\n 'onProps',\n];\n\nexport enum ExtensionPermission {\n INPUT = 'INPUT',\n FORM = 'FORM',\n API = 'API',\n}\n\ntype ConfigVariableName = string;\n\ntype ConfigVariableSettings = {\n type: 'string' | 'number' | 'boolean';\n displayName?: string;\n description?: string;\n required?: boolean;\n defaultValue?: any;\n};\n\nexport type ConfigFields = Record<ConfigVariableName, ConfigVariableSettings>;\n\nexport type ConfigValue = Record<\n string,\n boolean | number | string | undefined | null\n>;\n\nexport type FieldConfig = {\n tableConfig: ConfigValue;\n fieldConfig: ConfigValue;\n};\n\nexport type FormSidebarConfig = { sidebarConfig: ConfigValue };\n\nexport type Project = {\n id: string;\n name: string;\n mgmtApi: string;\n mgmtToken: string;\n};\n\nexport type Environment = {\n id: string;\n name: string;\n endpoint: string;\n authToken: string;\n};\n\nexport type Context = {\n project: Project;\n environment: Environment;\n};\n\nexport interface ExtensionPropsBase {\n context: Context;\n openDialog: OpenDialog;\n showToast: ShowToast;\n openAssetPicker: OpenAssetPicker;\n redirectParent: (location: string | Location) => Promise<void>;\n historyReplace: (url: string | HistoryCallback) => Promise<void>;\n historyPush: (url: string | HistoryCallback) => Promise<void>;\n}\n\nexport interface ExtensionDialogProps extends ExtensionPropsBase {\n onCloseDialog: (value: any) => void;\n}\n\ntype HistoryCallback = (href: Location['href']) => string;\n","import type { Form } from './type-helpers/form';\nimport type { ExtensionPropsBase, ConfigValue } from './base';\nimport type { Model } from './type-helpers/model';\nimport type { AppInstallation } from './type-helpers/appInstallation';\nimport type { Field } from './type-helpers/field';\n\nexport const FieldExtensionType = {\n STRING: 'STRING',\n RICHTEXT: 'RICHTEXT',\n INT: 'INT',\n FLOAT: 'FLOAT',\n BOOLEAN: 'BOOLEAN',\n JSON: 'JSON',\n DATETIME: 'DATETIME',\n DATE: 'DATE',\n LOCATION: 'LOCATION',\n COLOR: 'COLOR',\n ENUMERATION: 'ENUMERATION',\n RELATION: 'RELATION',\n ASSET: 'ASSET',\n UNION: 'UNION',\n} as const;\n\nexport const FieldExtensionFeature = {\n FieldRenderer: 'FieldRenderer',\n ListRenderer: 'ListRenderer',\n TableRenderer: 'TableRenderer',\n} as const;\n\nexport interface FieldExtensionProps extends ExtensionPropsBase {\n extension: {\n config: ConfigValue;\n tableConfig: ConfigValue;\n fieldConfig: ConfigValue;\n id: string;\n };\n\n isExpanded: boolean;\n expand: (expand: boolean | ((isExpanded: boolean) => boolean)) => unknown;\n\n // name of the field in the form (may differ from the field apiId, ie. for localized fields)\n name: string;\n\n // current locale on localized field\n locale: string | undefined;\n\n // current entry id, null for new entries;\n entryId: string | null;\n\n isTableCell: boolean;\n\n isReadOnly: boolean | undefined;\n\n value: any;\n\n onBlur: (event?: FocusEvent) => Promise<void>;\n\n onChange: (event: InputEvent | any) => Promise<void>;\n\n onFocus: (event?: FocusEvent) => Promise<void>;\n\n // @see https://final-form.org/docs/react-final-form/types/FieldRenderProps\n meta: {\n active: boolean;\n error: any;\n touched: boolean;\n };\n\n form: Form;\n field: Field;\n model: Model;\n installation: AppInstallation;\n}\n","import type { ConfigValue } from '../base';\n\nexport const AppInstallationStatus = {\n COMPLETED: 'COMPLETED',\n DISABLED: 'DISABLED',\n PENDING: 'PENDING',\n} as const;\n\nexport type AppInstallation = {\n id: string;\n config: ConfigValue;\n status: keyof typeof AppInstallationStatus;\n};\n","import zoid from '@graphcms/zoid/lib/zoid.js';\n\nimport { ExtensionDialogProps, reservedExtensionProps } from './base';\nexport { ExtensionDialogProps, reservedExtensionProps } from './base';\nimport type { FieldExtensionProps } from './field';\nimport type { FormSidebarExtensionProps } from './formSidebar';\nexport * from './base';\nexport type {\n FormState,\n FieldState,\n FieldSubscription,\n Subscriber,\n FormSubscription,\n Form,\n} from './type-helpers/form';\n\nexport type {\n VisibilityTypes,\n SetFieldsVisibility,\n VisibilityMap,\n} from './type-helpers/visibility';\n\nexport type { FieldExtensionProps } from './field';\nexport type { AppProps } from './app';\nexport type { FormSidebarExtensionProps } from './formSidebar';\nexport { FieldExtensionFeature, FieldExtensionType } from './field';\nexport * from './type-helpers/appInstallation';\n\nexport type ExtensionProps =\n | FieldExtensionProps\n | FormSidebarExtensionProps\n | ExtensionDialogProps;\n\ntype Xprops = {\n onProps: (props: Record<string, any>) => void;\n onConnected: (uid: string) => Promise<unknown>;\n resize: (size: {\n height: 'auto' | 'full' | number;\n width: 'auto' | '100%' | number;\n }) => unknown;\n} & ExtensionProps;\n\ndeclare global {\n interface Window {\n xprops: Xprops;\n }\n}\n\nfunction handleProps(props: any) {\n const transformedProps: any = {};\n Object.keys(props).forEach((key: string) => {\n // do not pass down zoid props to the extension\n if (reservedExtensionProps.includes(key)) return;\n\n // transform props that were prefixed with '_' to bypass zoid reverved props\n if (\n key.startsWith('_') &&\n reservedExtensionProps.includes(key.replace(/^_/g, ''))\n ) {\n transformedProps[key.replace(/^_/g, '')] = props[key];\n } else {\n transformedProps[key] = props[key];\n }\n });\n return transformedProps;\n}\n\nexport function init({\n debug,\n onProps = () => undefined,\n uid: givenUid,\n}: {\n onProps: (props: any) => unknown;\n debug?: boolean;\n uid?: string;\n}) {\n return new Promise<{ status: 'ok'; props: any } | { status: 'validation' }>(\n (resolve, reject) => {\n if (\n typeof window === 'undefined' ||\n typeof window.postMessage === 'undefined'\n ) {\n return reject({\n error: 'unsupported_env',\n message:\n 'Unsupported environment: Not in a browser supporting PostMessage',\n });\n }\n\n const uid =\n givenUid ||\n (typeof URLSearchParams !== 'undefined' &&\n new URLSearchParams(window.location.search).get('extensionUid'));\n\n if (!uid) {\n if (debug)\n console.error(`[UIX] no uid found in init params or extension URL`);\n return reject({\n error: 'missing_uid',\n message: 'Missing UID: no UID found in init params or extension URL',\n });\n }\n if (debug) console.info(`[UIX:${uid}] initializing with uid ${uid}`);\n\n zoid.create({\n tag: uid,\n url: window.location.href.toString(),\n autoResize: {\n width: false,\n height: true,\n element: 'html',\n },\n props: {\n onConnected: {\n type: 'function',\n },\n },\n });\n if (typeof window.xprops !== 'undefined') {\n const { onConnected, onProps: initialOnProps } = window.xprops;\n\n onConnected(uid).then((status) => {\n if (status === true) {\n const {\n onProps: onParentProps,\n onConnected: _nevermind,\n resize,\n ...extensionProps\n } = window.xprops;\n\n if (debug)\n console.info(`[UIX:${uid}] initial shared props`, extensionProps);\n onParentProps((p: Xprops) => {\n const {\n onProps: onParentProps,\n onConnected,\n ...newExtensionProps\n } = p;\n\n if (debug)\n console.info(\n `[UIX:${uid}] new shared props`,\n newExtensionProps\n );\n if ('isExpanded' in p && typeof p.isExpanded === 'boolean') {\n p.isExpanded\n ? resize({ height: 'full', width: '100%' })\n : resize({ height: 'auto', width: '100%' });\n }\n onProps(handleProps(newExtensionProps));\n });\n\n if (debug) console.info(`[UIX:${uid}] initialized`);\n onProps(handleProps(extensionProps));\n resolve({ status: 'ok', props: handleProps(extensionProps) });\n } else {\n if (debug)\n console.info(\n `[UIX:${uid}] sdk renderer returned status:`,\n status\n );\n resolve({ status: 'validation' });\n }\n });\n } else {\n if (debug) console.error(`[UIX] no shared props from host found`);\n reject({\n error: 'failed_communication',\n message:\n 'No communication established with host, please check your URL',\n });\n }\n }\n );\n}\n\nexport default { init };\n"],"names":["reservedExtensionProps","ExtensionPermission","FieldExtensionType","STRING","RICHTEXT","INT","FLOAT","BOOLEAN","JSON","DATETIME","DATE","LOCATION","COLOR","ENUMERATION","RELATION","ASSET","UNION","FieldExtensionFeature","FieldRenderer","ListRenderer","TableRenderer","AppInstallationStatus","COMPLETED","DISABLED","PENDING","handleProps","props","transformedProps","Object","keys","forEach","key","includes","startsWith","replace","init","debug","onProps","undefined","givenUid","uid","Promise","resolve","reject","window","postMessage","error","message","URLSearchParams","location","search","get","console","info","zoid","create","tag","url","href","toString","autoResize","width","height","element","onConnected","type","xprops","then","status","onParentProps","_nevermind","resize","extensionProps","p","newExtensionProps","isExpanded"],"mappings":";;;;;;;;;;;;;;;AAIA;IACaA,sBAAsB,GAAG,CACpC,SAAS,EACT,QAAQ,EACR,OAAO,EACP,OAAO,EACP,QAAQ,EACR,KAAK,EACL,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,MAAM,EACN,MAAM,EACN,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,UAAU,EACV,SAAS,EACT,WAAW,EACX,UAAU,EACV,SAAS,EACT,SAAS,EACT,SAAS;IAGCC;AAAZ,WAAYA,mBAAmB;EAC7BA,sCAAe;EACfA,oCAAa;EACbA,kCAAW;AACb,CAAC,EAJWA,mBAAmB,KAAnBA,mBAAmB;;ICvBlBC,kBAAkB,GAAG;EAChCC,MAAM,EAAE,QAAQ;EAChBC,QAAQ,EAAE,UAAU;EACpBC,GAAG,EAAE,KAAK;EACVC,KAAK,EAAE,OAAO;EACdC,OAAO,EAAE,SAAS;EAClBC,IAAI,EAAE,MAAM;EACZC,QAAQ,EAAE,UAAU;EACpBC,IAAI,EAAE,MAAM;EACZC,QAAQ,EAAE,UAAU;EACpBC,KAAK,EAAE,OAAO;EACdC,WAAW,EAAE,aAAa;EAC1BC,QAAQ,EAAE,UAAU;EACpBC,KAAK,EAAE,OAAO;EACdC,KAAK,EAAE;CACC;AAEV,IAAaC,qBAAqB,GAAG;EACnCC,aAAa,EAAE,eAAe;EAC9BC,YAAY,EAAE,cAAc;EAC5BC,aAAa,EAAE;CACP;;ICzBGC,qBAAqB,GAAG;EACnCC,SAAS,EAAE,WAAW;EACtBC,QAAQ,EAAE,UAAU;EACpBC,O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AAQ,CAAC;;YAE/CxB,OAAO,CAACZ,WAAW,CAACiD,iBAAiB,CAAC,CAAC;WACxC,CAAC;UAEF,IAAItC,KAAK,EAAEgB,OAAO,CAACC,IAAI,WAASb,GAAG,mBAAgB;UACnDH,OAAO,CAACZ,WAAW,CAAC+C,cAAc,CAAC,CAAC;UACpC9B,OAAO,CAAC;YAAE0B,MAAM,EAAE,IAAI;YAAE1C,KAAK,EAAED,WAAW,CAAC+C,cAAc;WAAG,CAAC;SAC9D,MAAM;UACL,IAAIpC,KAAK,EACPgB,OAAO,CAACC,IAAI,WACFb,GAAG,sCACX4B,MAAM,CACP;UACH1B,OAAO,CAAC;YAAE0B,MAAM,EAAE;WAAc,CAAC;;OAEpC,CAAC;KACH,MAAM;MACL,IAAIhC,KAAK,EAAEgB,OAAO,CAACN,KAAK,yCAAyC;MACjEH,MAAM,CAAC;QACLG,KAAK,EAAE,sBAAsB;QAC7BC,OAAO,EACL;OACH,CAAC;;GAEL,CACF;AACH;AAEA,YAAe;EAAEZ,IAAI,EAAJA;CAAM;;;;;"}
@@ -0,0 +1,171 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@graphcms/zoid/lib/zoid.js')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', '@graphcms/zoid/lib/zoid.js'], factory) :
4
+ (global = global || self, factory(global['@hygraph/app-sdk'] = {}, global.zoid));
5
+ }(this, (function (exports, zoid) { 'use strict';
6
+
7
+ zoid = zoid && Object.prototype.hasOwnProperty.call(zoid, 'default') ? zoid['default'] : zoid;
8
+
9
+ function _objectWithoutPropertiesLoose(source, excluded) {
10
+ if (source == null) return {};
11
+ var target = {};
12
+ var sourceKeys = Object.keys(source);
13
+ var key, i;
14
+ for (i = 0; i < sourceKeys.length; i++) {
15
+ key = sourceKeys[i];
16
+ if (excluded.indexOf(key) >= 0) continue;
17
+ target[key] = source[key];
18
+ }
19
+ return target;
20
+ }
21
+
22
+ // see https://github.com/krakenjs/zoid/blob/master/src/component/props.js#L53
23
+ var reservedExtensionProps = ['timeout', 'window', 'close', 'focus', 'resize', 'uid', 'cspNonce', 'getParent', 'getParentDomain', 'hide', 'show', 'export', 'onDisplay', 'onRendered', 'onRender', 'onClose', 'onDestroy', 'onResize', 'onFocus', 'onError', 'onProps'];
24
+ (function (ExtensionPermission) {
25
+ ExtensionPermission["INPUT"] = "INPUT";
26
+ ExtensionPermission["FORM"] = "FORM";
27
+ ExtensionPermission["API"] = "API";
28
+ })(exports.ExtensionPermission || (exports.ExtensionPermission = {}));
29
+
30
+ var FieldExtensionType = {
31
+ STRING: 'STRING',
32
+ RICHTEXT: 'RICHTEXT',
33
+ INT: 'INT',
34
+ FLOAT: 'FLOAT',
35
+ BOOLEAN: 'BOOLEAN',
36
+ JSON: 'JSON',
37
+ DATETIME: 'DATETIME',
38
+ DATE: 'DATE',
39
+ LOCATION: 'LOCATION',
40
+ COLOR: 'COLOR',
41
+ ENUMERATION: 'ENUMERATION',
42
+ RELATION: 'RELATION',
43
+ ASSET: 'ASSET',
44
+ UNION: 'UNION'
45
+ };
46
+ var FieldExtensionFeature = {
47
+ FieldRenderer: 'FieldRenderer',
48
+ ListRenderer: 'ListRenderer',
49
+ TableRenderer: 'TableRenderer'
50
+ };
51
+
52
+ var AppInstallationStatus = {
53
+ COMPLETED: 'COMPLETED',
54
+ DISABLED: 'DISABLED',
55
+ PENDING: 'PENDING'
56
+ };
57
+
58
+ var _excluded = ["onProps", "onConnected", "resize"],
59
+ _excluded2 = ["onProps", "onConnected"];
60
+ function handleProps(props) {
61
+ var transformedProps = {};
62
+ Object.keys(props).forEach(function (key) {
63
+ // do not pass down zoid props to the extension
64
+ if (reservedExtensionProps.includes(key)) return;
65
+ // transform props that were prefixed with '_' to bypass zoid reverved props
66
+ if (key.startsWith('_') && reservedExtensionProps.includes(key.replace(/^_/g, ''))) {
67
+ transformedProps[key.replace(/^_/g, '')] = props[key];
68
+ } else {
69
+ transformedProps[key] = props[key];
70
+ }
71
+ });
72
+ return transformedProps;
73
+ }
74
+ function init(_ref) {
75
+ var debug = _ref.debug,
76
+ _ref$onProps = _ref.onProps,
77
+ onProps = _ref$onProps === void 0 ? function () {
78
+ return undefined;
79
+ } : _ref$onProps,
80
+ givenUid = _ref.uid;
81
+ return new Promise(function (resolve, reject) {
82
+ if (typeof window === 'undefined' || typeof window.postMessage === 'undefined') {
83
+ return reject({
84
+ error: 'unsupported_env',
85
+ message: 'Unsupported environment: Not in a browser supporting PostMessage'
86
+ });
87
+ }
88
+ var uid = givenUid || typeof URLSearchParams !== 'undefined' && new URLSearchParams(window.location.search).get('extensionUid');
89
+ if (!uid) {
90
+ if (debug) console.error("[UIX] no uid found in init params or extension URL");
91
+ return reject({
92
+ error: 'missing_uid',
93
+ message: 'Missing UID: no UID found in init params or extension URL'
94
+ });
95
+ }
96
+ if (debug) console.info("[UIX:" + uid + "] initializing with uid " + uid);
97
+ zoid.create({
98
+ tag: uid,
99
+ url: window.location.href.toString(),
100
+ autoResize: {
101
+ width: false,
102
+ height: true,
103
+ element: 'html'
104
+ },
105
+ props: {
106
+ onConnected: {
107
+ type: 'function'
108
+ }
109
+ }
110
+ });
111
+ if (typeof window.xprops !== 'undefined') {
112
+ var _window$xprops = window.xprops,
113
+ onConnected = _window$xprops.onConnected;
114
+ onConnected(uid).then(function (status) {
115
+ if (status === true) {
116
+ var _window$xprops2 = window.xprops,
117
+ onParentProps = _window$xprops2.onProps,
118
+ resize = _window$xprops2.resize,
119
+ extensionProps = _objectWithoutPropertiesLoose(_window$xprops2, _excluded);
120
+ if (debug) console.info("[UIX:" + uid + "] initial shared props", extensionProps);
121
+ onParentProps(function (p) {
122
+ var newExtensionProps = _objectWithoutPropertiesLoose(p, _excluded2);
123
+ if (debug) console.info("[UIX:" + uid + "] new shared props", newExtensionProps);
124
+ if ('isExpanded' in p && typeof p.isExpanded === 'boolean') {
125
+ p.isExpanded ? resize({
126
+ height: 'full',
127
+ width: '100%'
128
+ }) : resize({
129
+ height: 'auto',
130
+ width: '100%'
131
+ });
132
+ }
133
+ onProps(handleProps(newExtensionProps));
134
+ });
135
+ if (debug) console.info("[UIX:" + uid + "] initialized");
136
+ onProps(handleProps(extensionProps));
137
+ resolve({
138
+ status: 'ok',
139
+ props: handleProps(extensionProps)
140
+ });
141
+ } else {
142
+ if (debug) console.info("[UIX:" + uid + "] sdk renderer returned status:", status);
143
+ resolve({
144
+ status: 'validation'
145
+ });
146
+ }
147
+ });
148
+ } else {
149
+ if (debug) console.error("[UIX] no shared props from host found");
150
+ reject({
151
+ error: 'failed_communication',
152
+ message: 'No communication established with host, please check your URL'
153
+ });
154
+ }
155
+ });
156
+ }
157
+ var index = {
158
+ init: init
159
+ };
160
+
161
+ exports.AppInstallationStatus = AppInstallationStatus;
162
+ exports.FieldExtensionFeature = FieldExtensionFeature;
163
+ exports.FieldExtensionType = FieldExtensionType;
164
+ exports.default = index;
165
+ exports.init = init;
166
+ exports.reservedExtensionProps = reservedExtensionProps;
167
+
168
+ Object.defineProperty(exports, '__esModule', { value: true });
169
+
170
+ })));
171
+ //# sourceMappingURL=app-sdk.umd.development.js.map