@hygraph/app-sdk 0.0.5 → 0.0.7

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.
@@ -6,17 +6,14 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
6
6
 
7
7
  var zoid = _interopDefault(require('@graphcms/zoid/lib/zoid.js'));
8
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];
9
+ function _objectWithoutPropertiesLoose(r, e) {
10
+ if (null == r) return {};
11
+ var t = {};
12
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
13
+ if (-1 !== e.indexOf(n)) continue;
14
+ t[n] = r[n];
18
15
  }
19
- return target;
16
+ return t;
20
17
  }
21
18
 
22
19
  // see https://github.com/krakenjs/zoid/blob/master/src/component/props.js#L53
@@ -1 +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 User = {\n id: string;\n};\n\nexport type Context = {\n /**\n * The project that the app is running in\n */\n project: Project;\n /**\n * The environment that the app is running in\n */\n environment: Environment;\n /**\n * The user that is currently logged in\n * Available only to apps that have read User permission\n *\n * Intended to be used to fetch user's permissions and roles\n * from the management API using the user's ID.\n *\n * @example\n * ```graphql\n * query user_query($id: ID!) {\n * viewer {\n * ... on AppTokenViewer {\n * id\n * user(id: $id) {\n * permissions\n * roles {\n * name\n * isDefault\n * }\n * }\n * }\n * }\n * }\n * ```\n */\n user?: User;\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,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,OAAO,EAAE;CACD;;;;ACNV,AAgDA,SAASC,WAAW,CAACC,KAAU;EAC7B,IAAMC,gBAAgB,GAAQ,EAAE;EAChCC,MAAM,CAACC,IAAI,CAACH,KAAK,CAAC,CAACI,OAAO,CAAC,UAACC,GAAW;;IAErC,IAAI/B,sBAAsB,C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AC,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;;;;;;;;;"}
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 User = {\n id: string;\n};\n\nexport type Context = {\n /**\n * The project that the app is running in\n */\n project: Project;\n /**\n * The environment that the app is running in\n */\n environment: Environment;\n /**\n * The user that is currently logged in\n * Available only to apps that have read User permission\n *\n * Intended to be used to fetch user's permissions and roles\n * from the management API using the user's ID.\n *\n * @example\n * ```graphql\n * query user_query($id: ID!) {\n * viewer {\n * ... on AppTokenViewer {\n * id\n * user(id: $id) {\n * permissions\n * roles {\n * name\n * isDefault\n * }\n * }\n * }\n * }\n * }\n * ```\n */\n user?: User;\n};\n\nexport interface ExtensionPropsBase {\n context: Context;\n openDialog: OpenDialog;\n showToast: ShowToast;\n openAssetPicker: OpenAssetPicker;\n reloadPage: () => void;\n clearSearchParams: () => void;\n}\n\nexport interface ExtensionDialogProps extends ExtensionPropsBase {\n onCloseDialog: (value: any) => void;\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","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","_ref","debug","_ref$onProps","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","_window$xprops","then","status","_window$xprops2","onParentProps","_nevermind","resize","extensionProps","_objectWithoutPropertiesLoose","_excluded","p","newExtensionProps","_excluded2","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,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AAO,CAAC;YAAE2B,MAAM,EAAE,IAAI;YAAE7C,KAAK,EAAED,WAAW,CAACmD,cAAc;WAAG,CAAC;SAC9D,MAAM;UACL,IAAIvC,KAAK,EACPiB,OAAO,CAACC,IAAI,WACFb,GAAG,sCACX6B,MAAM,CACP;UACH3B,OAAO,CAAC;YAAE2B,MAAM,EAAE;WAAc,CAAC;;OAEpC,CAAC;KACH,MAAM;MACL,IAAIlC,KAAK,EAAEiB,OAAO,CAACN,KAAK,wCAAwC,CAAC;MACjEH,MAAM,CAAC;QACLG,KAAK,EAAE,sBAAsB;QAC7BC,OAAO,EACL;OACH,CAAC;;GAEL,CACF;AACH;AAEA,YAAe;EAAEd,IAAI,EAAJA;CAAM;;;;;;;;;"}
@@ -1,2 +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;
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={};for(var i in e)if({}.hasOwnProperty.call(e,i)){if(-1!==n.indexOf(i))continue;o[i]=e[i]}return o}var i,r=["timeout","window","close","focus","resize","uid","cspNonce","getParent","getParentDomain","hide","show","export","onDisplay","onRendered","onRender","onClose","onDestroy","onResize","onFocus","onError","onProps"];(i=exports.ExtensionPermission||(exports.ExtensionPermission={})).INPUT="INPUT",i.FORM="FORM",i.API="API";var t=["onProps","onConnected","resize"],s=["onProps","onConnected"];function a(e){var n={};return Object.keys(e).forEach((function(o){r.includes(o)||(o.startsWith("_")&&r.includes(o.replace(/^_/g,""))?n[o.replace(/^_/g,"")]=e[o]:n[o]=e[o])})),n}function d(e){var i=e.debug,r=e.onProps,d=void 0===r?function(){}:r,p=e.uid;return new Promise((function(e,r){if("undefined"==typeof window||void 0===window.postMessage)return r({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 i&&console.error("[UIX] no uid found in init params or extension URL"),r({error:"missing_uid",message:"Missing UID: no UID found in init params or extension URL"});i&&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 r=window.xprops,p=r.onProps,c=r.resize,l=o(r,t);i&&console.info("[UIX:"+u+"] initial shared props",l),p((function(e){var n=o(e,s);i&&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%"}),d(a(n))})),i&&console.info("[UIX:"+u+"] initialized"),d(a(l)),e({status:"ok",props:a(l)})}else i&&console.info("[UIX:"+u+"] sdk renderer returned status:",n),e({status:"validation"})})):(i&&console.error("[UIX] no shared props from host found"),r({error:"failed_communication",message:"No communication established with host, please check your URL"}))}))}var p={init:d};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=d,exports.reservedExtensionProps=r;
2
2
  //# sourceMappingURL=app-sdk.cjs.production.min.js.map
@@ -1 +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 User = {\n id: string;\n};\n\nexport type Context = {\n /**\n * The project that the app is running in\n */\n project: Project;\n /**\n * The environment that the app is running in\n */\n environment: Environment;\n /**\n * The user that is currently logged in\n * Available only to apps that have read User permission\n *\n * Intended to be used to fetch user's permissions and roles\n * from the management API using the user's ID.\n *\n * @example\n * ```graphql\n * query user_query($id: ID!) {\n * viewer {\n * ... on AppTokenViewer {\n * id\n * user(id: $id) {\n * permissions\n * roles {\n * name\n * isDefault\n * }\n * }\n * }\n * }\n * }\n * ```\n */\n user?: User;\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,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,UAEvCpC,GACFgB,QAAQC,aACEb,oCACR4B,GAEJ1B,EAAQ,CAAE0B,OAAQ,mBAIlBhC,GAAOgB,QAAQN,+CACnBH,EAAO,CACLG,MAAO,uBACPC,QACE,sEAOZ,MAAe,CAAEZ,KAAAA,iCC9KoB,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"}
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 User = {\n id: string;\n};\n\nexport type Context = {\n /**\n * The project that the app is running in\n */\n project: Project;\n /**\n * The environment that the app is running in\n */\n environment: Environment;\n /**\n * The user that is currently logged in\n * Available only to apps that have read User permission\n *\n * Intended to be used to fetch user's permissions and roles\n * from the management API using the user's ID.\n *\n * @example\n * ```graphql\n * query user_query($id: ID!) {\n * viewer {\n * ... on AppTokenViewer {\n * id\n * user(id: $id) {\n * permissions\n * roles {\n * name\n * isDefault\n * }\n * }\n * }\n * }\n * }\n * ```\n */\n user?: User;\n};\n\nexport interface ExtensionPropsBase {\n context: Context;\n openDialog: OpenDialog;\n showToast: ShowToast;\n openAssetPicker: OpenAssetPicker;\n reloadPage: () => void;\n clearSearchParams: () => void;\n}\n\nexport interface ExtensionDialogProps extends ExtensionPropsBase {\n onCloseDialog: (value: any) => void;\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","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","_ref","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","_window$xprops2","onParentProps","_nevermind","resize","extensionProps","_objectWithoutPropertiesLoose","_excluded","p","newExtensionProps","_excluded2","isExpanded","COMPLETED","DISABLED","PENDING","FieldRenderer","ListRenderer","TableRenderer","STRING","RICHTEXT","INT","FLOAT","BOOLEAN","JSON","DATETIME","DATE","LOCATION","COLOR","ENUMERATION","RELATION","ASSET","UNION"],"mappings":"sTA6BYA,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,KAA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D,MAAO,QACzB,CAAEC,OAAQ,OAAQD,MAAO,SAEtCvB,EAAQd,EAAYqD,OAGlBzC,GAAOgB,QAAQC,aAAab,mBAChCF,EAAQd,EAAYiD,IACpB/B,EAAQ,CAAE0B,OAAQ,KAAM3C,MAAOD,EAAYiD,UAEvCrC,GACFgB,QAAQC,aACEb,oCACR4B,GAEJ1B,EAAQ,CAAE0B,OAAQ,mBAIlBhC,GAAOgB,QAAQN,+CACnBH,EAAO,CACLG,MAAO,uBACPC,QACE,sEAOZ,MAAe,CAAEb,KAAAA,iCC9KoB,CACnC8C,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"}
@@ -1,16 +1,13 @@
1
1
  import zoid from '@graphcms/zoid/lib/zoid.js';
2
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];
3
+ function _objectWithoutPropertiesLoose(r, e) {
4
+ if (null == r) return {};
5
+ var t = {};
6
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
7
+ if (-1 !== e.indexOf(n)) continue;
8
+ t[n] = r[n];
12
9
  }
13
- return target;
10
+ return t;
14
11
  }
15
12
 
16
13
  // see https://github.com/krakenjs/zoid/blob/master/src/component/props.js#L53
@@ -1 +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 User = {\n id: string;\n};\n\nexport type Context = {\n /**\n * The project that the app is running in\n */\n project: Project;\n /**\n * The environment that the app is running in\n */\n environment: Environment;\n /**\n * The user that is currently logged in\n * Available only to apps that have read User permission\n *\n * Intended to be used to fetch user's permissions and roles\n * from the management API using the user's ID.\n *\n * @example\n * ```graphql\n * query user_query($id: ID!) {\n * viewer {\n * ... on AppTokenViewer {\n * id\n * user(id: $id) {\n * permissions\n * roles {\n * name\n * isDefault\n * }\n * }\n * }\n * }\n * }\n * ```\n */\n user?: User;\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,QA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,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;;;;;"}
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 User = {\n id: string;\n};\n\nexport type Context = {\n /**\n * The project that the app is running in\n */\n project: Project;\n /**\n * The environment that the app is running in\n */\n environment: Environment;\n /**\n * The user that is currently logged in\n * Available only to apps that have read User permission\n *\n * Intended to be used to fetch user's permissions and roles\n * from the management API using the user's ID.\n *\n * @example\n * ```graphql\n * query user_query($id: ID!) {\n * viewer {\n * ... on AppTokenViewer {\n * id\n * user(id: $id) {\n * permissions\n * roles {\n * name\n * isDefault\n * }\n * }\n * }\n * }\n * }\n * ```\n */\n user?: User;\n};\n\nexport interface ExtensionPropsBase {\n context: Context;\n openDialog: OpenDialog;\n showToast: ShowToast;\n openAssetPicker: OpenAssetPicker;\n reloadPage: () => void;\n clearSearchParams: () => void;\n}\n\nexport interface ExtensionDialogProps extends ExtensionPropsBase {\n onCloseDialog: (value: any) => void;\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","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","_ref","debug","_ref$onProps","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","_window$xprops","then","status","_window$xprops2","onParentProps","_nevermind","resize","extensionProps","_objectWithoutPropertiesLoose","_excluded","p","newExtensionProps","_excluded2","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;E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,CAAC,IAAI,OAAOA,CAAC,CAACG,UAAU,KAAK,SAAS,EAAE;cAC1DH,CAAC,CAACG,UAAU,GACRP,MAAM,CAAC;gBAAEX,MAAM,EAAE,MAAM;gBAAED,KAAK,EAAE;eAAQ,CAAC,GACzCY,MAAM,CAAC;gBAAEX,MAAM,EAAE,MAAM;gBAAED,KAAK,EAAE;eAAQ,CAAC;;YAE/CxB,OAAO,CAACd,WAAW,CAACuD,iBAAiB,CAAC,CAAC;WACxC,CAAC;UAEF,IAAI3C,KAAK,EAAEiB,OAAO,CAACC,IAAI,WAASb,GAAG,kBAAe,CAAC;UACnDH,OAAO,CAACd,WAAW,CAACmD,cAAc,CAAC,CAAC;UACpChC,OAAO,CAAC;YAAE2B,MAAM,EAAE,IAAI;YAAE7C,KAAK,EAAED,WAAW,CAACmD,cAAc;WAAG,CAAC;SAC9D,MAAM;UACL,IAAIvC,KAAK,EACPiB,OAAO,CAACC,IAAI,WACFb,GAAG,sCACX6B,MAAM,CACP;UACH3B,OAAO,CAAC;YAAE2B,MAAM,EAAE;WAAc,CAAC;;OAEpC,CAAC;KACH,MAAM;MACL,IAAIlC,KAAK,EAAEiB,OAAO,CAACN,KAAK,wCAAwC,CAAC;MACjEH,MAAM,CAAC;QACLG,KAAK,EAAE,sBAAsB;QAC7BC,OAAO,EACL;OACH,CAAC;;GAEL,CACF;AACH;AAEA,YAAe;EAAEd,IAAI,EAAJA;CAAM;;;;;"}
@@ -6,17 +6,14 @@
6
6
 
7
7
  zoid = zoid && Object.prototype.hasOwnProperty.call(zoid, 'default') ? zoid['default'] : zoid;
8
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];
9
+ function _objectWithoutPropertiesLoose(r, e) {
10
+ if (null == r) return {};
11
+ var t = {};
12
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
13
+ if (-1 !== e.indexOf(n)) continue;
14
+ t[n] = r[n];
18
15
  }
19
- return target;
16
+ return t;
20
17
  }
21
18
 
22
19
  // see https://github.com/krakenjs/zoid/blob/master/src/component/props.js#L53
@@ -1 +1 @@
1
- {"version":3,"file":"app-sdk.umd.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 User = {\n id: string;\n};\n\nexport type Context = {\n /**\n * The project that the app is running in\n */\n project: Project;\n /**\n * The environment that the app is running in\n */\n environment: Environment;\n /**\n * The user that is currently logged in\n * Available only to apps that have read User permission\n *\n * Intended to be used to fetch user's permissions and roles\n * from the management API using the user's ID.\n *\n * @example\n * ```graphql\n * query user_query($id: ID!) {\n * viewer {\n * ... on AppTokenViewer {\n * id\n * user(id: $id) {\n * permissions\n * roles {\n * name\n * isDefault\n * }\n * }\n * }\n * }\n * }\n * ```\n */\n user?: User;\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":";;;;;;;;;;;;;;;;;;;;;EAIA;MACaA,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;EAGX,WAAYC,mBAAmB;IAC7BA,sCAAe;IACfA,oCAAa;IACbA,kCAAW;EACb,CAAC,EAJWA,2BAAmB,KAAnBA,2BAAmB;;MCv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;;;;;"}
1
+ {"version":3,"file":"app-sdk.umd.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 User = {\n id: string;\n};\n\nexport type Context = {\n /**\n * The project that the app is running in\n */\n project: Project;\n /**\n * The environment that the app is running in\n */\n environment: Environment;\n /**\n * The user that is currently logged in\n * Available only to apps that have read User permission\n *\n * Intended to be used to fetch user's permissions and roles\n * from the management API using the user's ID.\n *\n * @example\n * ```graphql\n * query user_query($id: ID!) {\n * viewer {\n * ... on AppTokenViewer {\n * id\n * user(id: $id) {\n * permissions\n * roles {\n * name\n * isDefault\n * }\n * }\n * }\n * }\n * }\n * ```\n */\n user?: User;\n};\n\nexport interface ExtensionPropsBase {\n context: Context;\n openDialog: OpenDialog;\n showToast: ShowToast;\n openAssetPicker: OpenAssetPicker;\n reloadPage: () => void;\n clearSearchParams: () => void;\n}\n\nexport interface ExtensionDialogProps extends ExtensionPropsBase {\n onCloseDialog: (value: any) => void;\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","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","_ref","debug","_ref$onProps","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","_window$xprops","then","status","_window$xprops2","onParentProps","_nevermind","resize","extensionProps","_objectWithoutPropertiesLoose","_excluded","p","newExtensionProps","_excluded2","isExpanded"],"mappings":";;;;;;;;;;;;;;;;;;EAIA;MACaA,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;EAGX,WAAYC,mBAAmB;IAC7BA,sCAAe;IACfA,oCAAa;IACbA,kCAAW;EACb,CAAC,EAJWA,2BAAmB,KAAnBA,2BAAmB;;MCvBlBC,kBAAkB,GAAG;IAChCC,MAAM,EAAE,QAAQ;IAChBC,QAAQ,EAAE,UAAU;IACpBC,GAAG,EAAE,KAAK;IACVC,KAAK,EAAE,OAAO;IACdC,OAAO,EAAE,SAAS;IAClBC,IAAI,EAAE,MAAM;IACZC,QAAQ,EAAE,UAAU;IACpBC,IAAI,EAAE,MAAM;IACZC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;;"}
@@ -1,2 +1,2 @@
1
- !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("@graphcms/zoid/lib/zoid.js")):"function"==typeof define&&define.amd?define(["exports","@graphcms/zoid/lib/zoid.js"],n):n((e=e||self)["@hygraph/app-sdk"]={},e.zoid)}(this,(function(e,n){"use strict";function o(e,n){if(null==e)return{};var o,i,r={},t=Object.keys(e);for(i=0;i<t.length;i++)n.indexOf(o=t[i])>=0||(r[o]=e[o]);return r}n=n&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n;var i,r=["timeout","window","close","focus","resize","uid","cspNonce","getParent","getParentDomain","hide","show","export","onDisplay","onRendered","onRender","onClose","onDestroy","onResize","onFocus","onError","onProps"];(i=e.ExtensionPermission||(e.ExtensionPermission={})).INPUT="INPUT",i.FORM="FORM",i.API="API";var t=["onProps","onConnected","resize"],s=["onProps","onConnected"];function d(e){var n={};return Object.keys(e).forEach((function(o){r.includes(o)||(o.startsWith("_")&&r.includes(o.replace(/^_/g,""))?n[o.replace(/^_/g,"")]=e[o]:n[o]=e[o])})),n}function a(e){var i=e.debug,r=e.onProps,a=void 0===r?function(){}:r,p=e.uid;return new Promise((function(e,r){if("undefined"==typeof window||void 0===window.postMessage)return r({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 i&&console.error("[UIX] no uid found in init params or extension URL"),r({error:"missing_uid",message:"Missing UID: no UID found in init params or extension URL"});i&&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 r=window.xprops,p=r.onProps,c=r.resize,l=o(r,t);i&&console.info("[UIX:"+u+"] initial shared props",l),p((function(e){var n=o(e,s);i&&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))})),i&&console.info("[UIX:"+u+"] initialized"),a(d(l)),e({status:"ok",props:d(l)})}else i&&console.info("[UIX:"+u+"] sdk renderer returned status:",n),e({status:"validation"})})):(i&&console.error("[UIX] no shared props from host found"),r({error:"failed_communication",message:"No communication established with host, please check your URL"}))}))}var p={init:a};e.AppInstallationStatus={COMPLETED:"COMPLETED",DISABLED:"DISABLED",PENDING:"PENDING"},e.FieldExtensionFeature={FieldRenderer:"FieldRenderer",ListRenderer:"ListRenderer",TableRenderer:"TableRenderer"},e.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"},e.default=p,e.init=a,e.reservedExtensionProps=r,Object.defineProperty(e,"__esModule",{value:!0})}));
1
+ !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("@graphcms/zoid/lib/zoid.js")):"function"==typeof define&&define.amd?define(["exports","@graphcms/zoid/lib/zoid.js"],n):n((e=e||self)["@hygraph/app-sdk"]={},e.zoid)}(this,(function(e,n){"use strict";function o(e,n){if(null==e)return{};var o={};for(var i in e)if({}.hasOwnProperty.call(e,i)){if(-1!==n.indexOf(i))continue;o[i]=e[i]}return o}n=n&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n;var i,r=["timeout","window","close","focus","resize","uid","cspNonce","getParent","getParentDomain","hide","show","export","onDisplay","onRendered","onRender","onClose","onDestroy","onResize","onFocus","onError","onProps"];(i=e.ExtensionPermission||(e.ExtensionPermission={})).INPUT="INPUT",i.FORM="FORM",i.API="API";var t=["onProps","onConnected","resize"],s=["onProps","onConnected"];function d(e){var n={};return Object.keys(e).forEach((function(o){r.includes(o)||(o.startsWith("_")&&r.includes(o.replace(/^_/g,""))?n[o.replace(/^_/g,"")]=e[o]:n[o]=e[o])})),n}function a(e){var i=e.debug,r=e.onProps,a=void 0===r?function(){}:r,p=e.uid;return new Promise((function(e,r){if("undefined"==typeof window||void 0===window.postMessage)return r({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 i&&console.error("[UIX] no uid found in init params or extension URL"),r({error:"missing_uid",message:"Missing UID: no UID found in init params or extension URL"});i&&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 r=window.xprops,p=r.onProps,c=r.resize,l=o(r,t);i&&console.info("[UIX:"+u+"] initial shared props",l),p((function(e){var n=o(e,s);i&&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))})),i&&console.info("[UIX:"+u+"] initialized"),a(d(l)),e({status:"ok",props:d(l)})}else i&&console.info("[UIX:"+u+"] sdk renderer returned status:",n),e({status:"validation"})})):(i&&console.error("[UIX] no shared props from host found"),r({error:"failed_communication",message:"No communication established with host, please check your URL"}))}))}var p={init:a};e.AppInstallationStatus={COMPLETED:"COMPLETED",DISABLED:"DISABLED",PENDING:"PENDING"},e.FieldExtensionFeature={FieldRenderer:"FieldRenderer",ListRenderer:"ListRenderer",TableRenderer:"TableRenderer"},e.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"},e.default=p,e.init=a,e.reservedExtensionProps=r,Object.defineProperty(e,"__esModule",{value:!0})}));
2
2
  //# sourceMappingURL=app-sdk.umd.production.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"app-sdk.umd.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 User = {\n id: string;\n};\n\nexport type Context = {\n /**\n * The project that the app is running in\n */\n project: Project;\n /**\n * The environment that the app is running in\n */\n environment: Environment;\n /**\n * The user that is currently logged in\n * Available only to apps that have read User permission\n *\n * Intended to be used to fetch user's permissions and roles\n * from the management API using the user's ID.\n *\n * @example\n * ```graphql\n * query user_query($id: ID!) {\n * viewer {\n * ... on AppTokenViewer {\n * id\n * user(id: $id) {\n * permissions\n * roles {\n * name\n * isDefault\n * }\n * }\n * }\n * }\n * }\n * ```\n */\n user?: User;\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":"weA6BYA,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,wBAAAA,yCAEVA,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,QAAAA,aA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AW,YACXC,SAAU,WACVC,QAAS,mCCkB0B,CACnCC,cAAe,gBACfC,aAAc,eACdC,cAAe,sCApBiB,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"}
1
+ {"version":3,"file":"app-sdk.umd.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 User = {\n id: string;\n};\n\nexport type Context = {\n /**\n * The project that the app is running in\n */\n project: Project;\n /**\n * The environment that the app is running in\n */\n environment: Environment;\n /**\n * The user that is currently logged in\n * Available only to apps that have read User permission\n *\n * Intended to be used to fetch user's permissions and roles\n * from the management API using the user's ID.\n *\n * @example\n * ```graphql\n * query user_query($id: ID!) {\n * viewer {\n * ... on AppTokenViewer {\n * id\n * user(id: $id) {\n * permissions\n * roles {\n * name\n * isDefault\n * }\n * }\n * }\n * }\n * }\n * ```\n */\n user?: User;\n};\n\nexport interface ExtensionPropsBase {\n context: Context;\n openDialog: OpenDialog;\n showToast: ShowToast;\n openAssetPicker: OpenAssetPicker;\n reloadPage: () => void;\n clearSearchParams: () => void;\n}\n\nexport interface ExtensionDialogProps extends ExtensionPropsBase {\n onCloseDialog: (value: any) => void;\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","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","_ref","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","_window$xprops2","onParentProps","_nevermind","resize","extensionProps","_objectWithoutPropertiesLoose","_excluded","p","newExtensionProps","_excluded2","isExpanded","COMPLETED","DISABLED","PENDING","FieldRenderer","ListRenderer","TableRenderer","STRING","RICHTEXT","INT","FLOAT","BOOLEAN","JSON","DATETIME","DATE","LOCATION","COLOR","ENUMERATION","RELATION","ASSET","UNION"],"mappings":"ifA6BYA,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,wBAAAA,yCAEVA,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,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ACFgB,QAAQC,aACEb,oCACR4B,GAEJ1B,EAAQ,CAAE0B,OAAQ,mBAIlBhC,GAAOgB,QAAQN,+CACnBH,EAAO,CACLG,MAAO,uBACPC,QACE,4EAOG,CAAEb,KAAAA,2BC9KoB,CACnC8C,UAAW,YACXC,SAAU,WACVC,QAAS,mCCkB0B,CACnCC,cAAe,gBACfC,aAAc,eACdC,cAAe,sCApBiB,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"}
package/dist/base.d.ts CHANGED
@@ -80,12 +80,10 @@ export interface ExtensionPropsBase {
80
80
  openDialog: OpenDialog;
81
81
  showToast: ShowToast;
82
82
  openAssetPicker: OpenAssetPicker;
83
- redirectParent: (location: string | Location) => Promise<void>;
84
- historyReplace: (url: string | HistoryCallback) => Promise<void>;
85
- historyPush: (url: string | HistoryCallback) => Promise<void>;
83
+ reloadPage: () => void;
84
+ clearSearchParams: () => void;
86
85
  }
87
86
  export interface ExtensionDialogProps extends ExtensionPropsBase {
88
87
  onCloseDialog: (value: any) => void;
89
88
  }
90
- declare type HistoryCallback = (href: Location['href']) => string;
91
89
  export {};