@hygraph/app-sdk 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +15 -0
  2. package/dist/app-sdk.cjs.development.js +167 -0
  3. package/dist/app-sdk.cjs.development.js.map +1 -0
  4. package/dist/app-sdk.cjs.production.min.js +2 -0
  5. package/dist/app-sdk.cjs.production.min.js.map +1 -0
  6. package/dist/app-sdk.esm.js +158 -0
  7. package/dist/app-sdk.esm.js.map +1 -0
  8. package/dist/app-sdk.umd.development.js +171 -0
  9. package/dist/app-sdk.umd.development.js.map +1 -0
  10. package/dist/app-sdk.umd.production.min.js +2 -0
  11. package/dist/app-sdk.umd.production.min.js.map +1 -0
  12. package/dist/app.d.ts +8 -0
  13. package/dist/base.d.ts +56 -0
  14. package/dist/field.d.ts +54 -0
  15. package/dist/formSidebar.d.ts +27 -0
  16. package/dist/index.d.ts +40 -0
  17. package/dist/index.js +8 -0
  18. package/dist/type-helpers/appInstallation.d.ts +11 -0
  19. package/dist/type-helpers/dialog.d.ts +5 -0
  20. package/dist/type-helpers/field.d.ts +12 -0
  21. package/dist/type-helpers/form.d.ts +20 -0
  22. package/dist/type-helpers/locale.d.ts +9 -0
  23. package/dist/type-helpers/model.d.ts +8 -0
  24. package/dist/type-helpers/openAssetPicker.d.ts +13 -0
  25. package/dist/type-helpers/stage.d.ts +12 -0
  26. package/dist/type-helpers/toast.d.ts +14 -0
  27. package/dist/type-helpers/user.d.ts +8 -0
  28. package/dist/type-helpers/visibility.d.ts +5 -0
  29. package/package.json +41 -0
  30. package/src/app.ts +11 -0
  31. package/src/base.ts +93 -0
  32. package/src/declaration.d.ts +2 -0
  33. package/src/field.ts +73 -0
  34. package/src/formSidebar.ts +33 -0
  35. package/src/index.ts +177 -0
  36. package/src/type-helpers/appInstallation.ts +13 -0
  37. package/src/type-helpers/dialog.ts +11 -0
  38. package/src/type-helpers/field.ts +13 -0
  39. package/src/type-helpers/form.ts +44 -0
  40. package/src/type-helpers/locale.ts +10 -0
  41. package/src/type-helpers/model.ts +8 -0
  42. package/src/type-helpers/openAssetPicker.ts +16 -0
  43. package/src/type-helpers/stage.ts +21 -0
  44. package/src/type-helpers/toast.ts +30 -0
  45. package/src/type-helpers/user.ts +9 -0
  46. package/src/type-helpers/visibility.ts +7 -0
@@ -0,0 +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 Context = {\n project: Project;\n environment: Environment;\n};\n\nexport interface ExtensionPropsBase {\n context: Context;\n openDialog: OpenDialog;\n showToast: ShowToast;\n openAssetPicker: OpenAssetPicker;\n redirectParent: (location: string | Location) => Promise<void>;\n historyReplace: (url: string | HistoryCallback) => Promise<void>;\n historyPush: (url: string | HistoryCallback) => Promise<void>;\n}\n\nexport interface ExtensionDialogProps extends ExtensionPropsBase {\n onCloseDialog: (value: any) => void;\n}\n\ntype HistoryCallback = (href: Location['href']) => string;\n","import type { Form } from './type-helpers/form';\nimport type { ExtensionPropsBase, ConfigValue } from './base';\nimport type { Model } from './type-helpers/model';\nimport type { AppInstallation } from './type-helpers/appInstallation';\nimport type { Field } from './type-helpers/field';\n\nexport const FieldExtensionType = {\n STRING: 'STRING',\n RICHTEXT: 'RICHTEXT',\n INT: 'INT',\n FLOAT: 'FLOAT',\n BOOLEAN: 'BOOLEAN',\n JSON: 'JSON',\n DATETIME: 'DATETIME',\n DATE: 'DATE',\n LOCATION: 'LOCATION',\n COLOR: 'COLOR',\n ENUMERATION: 'ENUMERATION',\n RELATION: 'RELATION',\n ASSET: 'ASSET',\n UNION: 'UNION',\n} as const;\n\nexport const FieldExtensionFeature = {\n FieldRenderer: 'FieldRenderer',\n ListRenderer: 'ListRenderer',\n TableRenderer: 'TableRenderer',\n} as const;\n\nexport interface FieldExtensionProps extends ExtensionPropsBase {\n extension: {\n config: ConfigValue;\n tableConfig: ConfigValue;\n fieldConfig: ConfigValue;\n id: string;\n };\n\n isExpanded: boolean;\n expand: (expand: boolean | ((isExpanded: boolean) => boolean)) => unknown;\n\n // name of the field in the form (may differ from the field apiId, ie. for localized fields)\n name: string;\n\n // current locale on localized field\n locale: string | undefined;\n\n // current entry id, null for new entries;\n entryId: string | null;\n\n isTableCell: boolean;\n\n isReadOnly: boolean | undefined;\n\n value: any;\n\n onBlur: (event?: FocusEvent) => Promise<void>;\n\n onChange: (event: InputEvent | any) => Promise<void>;\n\n onFocus: (event?: FocusEvent) => Promise<void>;\n\n // @see https://final-form.org/docs/react-final-form/types/FieldRenderProps\n meta: {\n active: boolean;\n error: any;\n touched: boolean;\n };\n\n form: Form;\n field: Field;\n model: Model;\n installation: AppInstallation;\n}\n","import type { ConfigValue } from '../base';\n\nexport const AppInstallationStatus = {\n COMPLETED: 'COMPLETED',\n DISABLED: 'DISABLED',\n PENDING: 'PENDING',\n} as const;\n\nexport type AppInstallation = {\n id: string;\n config: ConfigValue;\n status: keyof typeof AppInstallationStatus;\n};\n","import zoid from '@graphcms/zoid/lib/zoid.js';\n\nimport { ExtensionDialogProps, reservedExtensionProps } from './base';\nexport { ExtensionDialogProps, reservedExtensionProps } from './base';\nimport type { FieldExtensionProps } from './field';\nimport type { FormSidebarExtensionProps } from './formSidebar';\nexport * from './base';\nexport type {\n FormState,\n FieldState,\n FieldSubscription,\n Subscriber,\n FormSubscription,\n Form,\n} from './type-helpers/form';\n\nexport type {\n VisibilityTypes,\n SetFieldsVisibility,\n VisibilityMap,\n} from './type-helpers/visibility';\n\nexport type { FieldExtensionProps } from './field';\nexport type { AppProps } from './app';\nexport type { FormSidebarExtensionProps } from './formSidebar';\nexport { FieldExtensionFeature, FieldExtensionType } from './field';\nexport * from './type-helpers/appInstallation';\n\nexport type ExtensionProps =\n | FieldExtensionProps\n | FormSidebarExtensionProps\n | ExtensionDialogProps;\n\ntype Xprops = {\n onProps: (props: Record<string, any>) => void;\n onConnected: (uid: string) => Promise<unknown>;\n resize: (size: {\n height: 'auto' | 'full' | number;\n width: 'auto' | '100%' | number;\n }) => unknown;\n} & ExtensionProps;\n\ndeclare global {\n interface Window {\n xprops: Xprops;\n }\n}\n\nfunction handleProps(props: any) {\n const transformedProps: any = {};\n Object.keys(props).forEach((key: string) => {\n // do not pass down zoid props to the extension\n if (reservedExtensionProps.includes(key)) return;\n\n // transform props that were prefixed with '_' to bypass zoid reverved props\n if (\n key.startsWith('_') &&\n reservedExtensionProps.includes(key.replace(/^_/g, ''))\n ) {\n transformedProps[key.replace(/^_/g, '')] = props[key];\n } else {\n transformedProps[key] = props[key];\n }\n });\n return transformedProps;\n}\n\nexport function init({\n debug,\n onProps = () => undefined,\n uid: givenUid,\n}: {\n onProps: (props: any) => unknown;\n debug?: boolean;\n uid?: string;\n}) {\n return new Promise<{ status: 'ok'; props: any } | { status: 'validation' }>(\n (resolve, reject) => {\n if (\n typeof window === 'undefined' ||\n typeof window.postMessage === 'undefined'\n ) {\n return reject({\n error: 'unsupported_env',\n message:\n 'Unsupported environment: Not in a browser supporting PostMessage',\n });\n }\n\n const uid =\n givenUid ||\n (typeof URLSearchParams !== 'undefined' &&\n new URLSearchParams(window.location.search).get('extensionUid'));\n\n if (!uid) {\n if (debug)\n console.error(`[UIX] no uid found in init params or extension URL`);\n return reject({\n error: 'missing_uid',\n message: 'Missing UID: no UID found in init params or extension URL',\n });\n }\n if (debug) console.info(`[UIX:${uid}] initializing with uid ${uid}`);\n\n zoid.create({\n tag: uid,\n url: window.location.href.toString(),\n autoResize: {\n width: false,\n height: true,\n element: 'html',\n },\n props: {\n onConnected: {\n type: 'function',\n },\n },\n });\n if (typeof window.xprops !== 'undefined') {\n const { onConnected, onProps: initialOnProps } = window.xprops;\n\n onConnected(uid).then((status) => {\n if (status === true) {\n const {\n onProps: onParentProps,\n onConnected: _nevermind,\n resize,\n ...extensionProps\n } = window.xprops;\n\n if (debug)\n console.info(`[UIX:${uid}] initial shared props`, extensionProps);\n onParentProps((p: Xprops) => {\n const {\n onProps: onParentProps,\n onConnected,\n ...newExtensionProps\n } = p;\n\n if (debug)\n console.info(\n `[UIX:${uid}] new shared props`,\n newExtensionProps\n );\n if ('isExpanded' in p && typeof p.isExpanded === 'boolean') {\n p.isExpanded\n ? resize({ height: 'full', width: '100%' })\n : resize({ height: 'auto', width: '100%' });\n }\n onProps(handleProps(newExtensionProps));\n });\n\n if (debug) console.info(`[UIX:${uid}] initialized`);\n onProps(handleProps(extensionProps));\n resolve({ status: 'ok', props: handleProps(extensionProps) });\n } else {\n if (debug)\n console.info(\n `[UIX:${uid}] sdk renderer returned status:`,\n status\n );\n resolve({ status: 'validation' });\n }\n });\n } else {\n if (debug) console.error(`[UIX] no shared props from host found`);\n reject({\n error: 'failed_communication',\n message:\n 'No communication established with host, please check your URL',\n });\n }\n }\n );\n}\n\nexport default { init };\n"],"names":["reservedExtensionProps","ExtensionPermission","FieldExtensionType","STRING","RICHTEXT","INT","FLOAT","BOOLEAN","JSON","DATETIME","DATE","LOCATION","COLOR","ENUMERATION","RELATION","ASSET","UNION","FieldExtensionFeature","FieldRenderer","ListRenderer","TableRenderer","AppInstallationStatus","COMPLETED","DISABLED","PENDING","handleProps","props","transformedProps","Object","keys","forEach","key","includes","startsWith","replace","init","debug","onProps","undefined","givenUid","uid","Promise","resolve","reject","window","postMessage","error","message","URLSearchParams","location","search","get","console","info","zoid","create","tag","url","href","toString","autoResize","width","height","element","onConnected","type","xprops","then","status","onParentProps","_nevermind","resize","extensionProps","p","newExtensionProps","isExpanded"],"mappings":";;;;;;;;;;;;;;;;;;;;;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,QAAQ,EAAE,UAAU;IACpBC,KAAK,EAA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AO,CAACC,IAAI,WACFb,GAAG,yBACXkC,iBAAiB,CAClB;cACH,IAAI,YAAY,IAAID,CAAC,IAAI,OAAOA,CAAC,CAACE,UAAU,KAAK,SAAS,EAAE;gBAC1DF,CAAC,CAACE,UAAU,GACRJ,MAAM,CAAC;kBAAET,MAAM,EAAE,MAAM;kBAAED,KAAK,EAAE;iBAAQ,CAAC,GACzCU,MAAM,CAAC;kBAAET,MAAM,EAAE,MAAM;kBAAED,KAAK,EAAE;iBAAQ,CAAC;;cAE/CxB,OAAO,CAACZ,WAAW,CAACiD,iBAAiB,CAAC,CAAC;aACxC,CAAC;YAEF,IAAItC,KAAK,EAAEgB,OAAO,CAACC,IAAI,WAASb,GAAG,mBAAgB;YACnDH,OAAO,CAACZ,WAAW,CAAC+C,cAAc,CAAC,CAAC;YACpC9B,OAAO,CAAC;cAAE0B,MAAM,EAAE,IAAI;cAAE1C,KAAK,EAAED,WAAW,CAAC+C,cAAc;aAAG,CAAC;WAC9D,MAAM;YACL,IAAIpC,KAAK,EACPgB,OAAO,CAACC,IAAI,WACFb,GAAG,sCACX4B,MAAM,CACP;YACH1B,OAAO,CAAC;cAAE0B,MAAM,EAAE;aAAc,CAAC;;SAEpC,CAAC;OACH,MAAM;QACL,IAAIhC,KAAK,EAAEgB,OAAO,CAACN,KAAK,yCAAyC;QACjEH,MAAM,CAAC;UACLG,KAAK,EAAE,sBAAsB;UAC7BC,OAAO,EACL;SACH,CAAC;;KAEL,CACF;EACH;AAEA,cAAe;IAAEZ,IAAI,EAAJA;GAAM;;;;;;;;;;;;;;;;;"}
@@ -0,0 +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})}));
2
+ //# sourceMappingURL=app-sdk.umd.production.min.js.map
@@ -0,0 +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 Context = {\n project: Project;\n environment: Environment;\n};\n\nexport interface ExtensionPropsBase {\n context: Context;\n openDialog: OpenDialog;\n showToast: ShowToast;\n openAssetPicker: OpenAssetPicker;\n redirectParent: (location: string | Location) => Promise<void>;\n historyReplace: (url: string | HistoryCallback) => Promise<void>;\n historyPush: (url: string | HistoryCallback) => Promise<void>;\n}\n\nexport interface ExtensionDialogProps extends ExtensionPropsBase {\n onCloseDialog: (value: any) => void;\n}\n\ntype HistoryCallback = (href: Location['href']) => string;\n","import zoid from '@graphcms/zoid/lib/zoid.js';\n\nimport { ExtensionDialogProps, reservedExtensionProps } from './base';\nexport { ExtensionDialogProps, reservedExtensionProps } from './base';\nimport type { FieldExtensionProps } from './field';\nimport type { FormSidebarExtensionProps } from './formSidebar';\nexport * from './base';\nexport type {\n FormState,\n FieldState,\n FieldSubscription,\n Subscriber,\n FormSubscription,\n Form,\n} from './type-helpers/form';\n\nexport type {\n VisibilityTypes,\n SetFieldsVisibility,\n VisibilityMap,\n} from './type-helpers/visibility';\n\nexport type { FieldExtensionProps } from './field';\nexport type { AppProps } from './app';\nexport type { FormSidebarExtensionProps } from './formSidebar';\nexport { FieldExtensionFeature, FieldExtensionType } from './field';\nexport * from './type-helpers/appInstallation';\n\nexport type ExtensionProps =\n | FieldExtensionProps\n | FormSidebarExtensionProps\n | ExtensionDialogProps;\n\ntype Xprops = {\n onProps: (props: Record<string, any>) => void;\n onConnected: (uid: string) => Promise<unknown>;\n resize: (size: {\n height: 'auto' | 'full' | number;\n width: 'auto' | '100%' | number;\n }) => unknown;\n} & ExtensionProps;\n\ndeclare global {\n interface Window {\n xprops: Xprops;\n }\n}\n\nfunction handleProps(props: any) {\n const transformedProps: any = {};\n Object.keys(props).forEach((key: string) => {\n // do not pass down zoid props to the extension\n if (reservedExtensionProps.includes(key)) return;\n\n // transform props that were prefixed with '_' to bypass zoid reverved props\n if (\n key.startsWith('_') &&\n reservedExtensionProps.includes(key.replace(/^_/g, ''))\n ) {\n transformedProps[key.replace(/^_/g, '')] = props[key];\n } else {\n transformedProps[key] = props[key];\n }\n });\n return transformedProps;\n}\n\nexport function init({\n debug,\n onProps = () => undefined,\n uid: givenUid,\n}: {\n onProps: (props: any) => unknown;\n debug?: boolean;\n uid?: string;\n}) {\n return new Promise<{ status: 'ok'; props: any } | { status: 'validation' }>(\n (resolve, reject) => {\n if (\n typeof window === 'undefined' ||\n typeof window.postMessage === 'undefined'\n ) {\n return reject({\n error: 'unsupported_env',\n message:\n 'Unsupported environment: Not in a browser supporting PostMessage',\n });\n }\n\n const uid =\n givenUid ||\n (typeof URLSearchParams !== 'undefined' &&\n new URLSearchParams(window.location.search).get('extensionUid'));\n\n if (!uid) {\n if (debug)\n console.error(`[UIX] no uid found in init params or extension URL`);\n return reject({\n error: 'missing_uid',\n message: 'Missing UID: no UID found in init params or extension URL',\n });\n }\n if (debug) console.info(`[UIX:${uid}] initializing with uid ${uid}`);\n\n zoid.create({\n tag: uid,\n url: window.location.href.toString(),\n autoResize: {\n width: false,\n height: true,\n element: 'html',\n },\n props: {\n onConnected: {\n type: 'function',\n },\n },\n });\n if (typeof window.xprops !== 'undefined') {\n const { onConnected, onProps: initialOnProps } = window.xprops;\n\n onConnected(uid).then((status) => {\n if (status === true) {\n const {\n onProps: onParentProps,\n onConnected: _nevermind,\n resize,\n ...extensionProps\n } = window.xprops;\n\n if (debug)\n console.info(`[UIX:${uid}] initial shared props`, extensionProps);\n onParentProps((p: Xprops) => {\n const {\n onProps: onParentProps,\n onConnected,\n ...newExtensionProps\n } = p;\n\n if (debug)\n console.info(\n `[UIX:${uid}] new shared props`,\n newExtensionProps\n );\n if ('isExpanded' in p && typeof p.isExpanded === 'boolean') {\n p.isExpanded\n ? resize({ height: 'full', width: '100%' })\n : resize({ height: 'auto', width: '100%' });\n }\n onProps(handleProps(newExtensionProps));\n });\n\n if (debug) console.info(`[UIX:${uid}] initialized`);\n onProps(handleProps(extensionProps));\n resolve({ status: 'ok', props: handleProps(extensionProps) });\n } else {\n if (debug)\n console.info(\n `[UIX:${uid}] sdk renderer returned status:`,\n status\n );\n resolve({ status: 'validation' });\n }\n });\n } else {\n if (debug) console.error(`[UIX] no shared props from host found`);\n reject({\n error: 'failed_communication',\n message:\n 'No communication established with host, please check your URL',\n });\n }\n }\n );\n}\n\nexport default { init };\n","import type { ConfigValue } from '../base';\n\nexport const AppInstallationStatus = {\n COMPLETED: 'COMPLETED',\n DISABLED: 'DISABLED',\n PENDING: 'PENDING',\n} as const;\n\nexport type AppInstallation = {\n id: string;\n config: ConfigValue;\n status: keyof typeof AppInstallationStatus;\n};\n","import type { Form } from './type-helpers/form';\nimport type { ExtensionPropsBase, ConfigValue } from './base';\nimport type { Model } from './type-helpers/model';\nimport type { AppInstallation } from './type-helpers/appInstallation';\nimport type { Field } from './type-helpers/field';\n\nexport const FieldExtensionType = {\n STRING: 'STRING',\n RICHTEXT: 'RICHTEXT',\n INT: 'INT',\n FLOAT: 'FLOAT',\n BOOLEAN: 'BOOLEAN',\n JSON: 'JSON',\n DATETIME: 'DATETIME',\n DATE: 'DATE',\n LOCATION: 'LOCATION',\n COLOR: 'COLOR',\n ENUMERATION: 'ENUMERATION',\n RELATION: 'RELATION',\n ASSET: 'ASSET',\n UNION: 'UNION',\n} as const;\n\nexport const FieldExtensionFeature = {\n FieldRenderer: 'FieldRenderer',\n ListRenderer: 'ListRenderer',\n TableRenderer: 'TableRenderer',\n} as const;\n\nexport interface FieldExtensionProps extends ExtensionPropsBase {\n extension: {\n config: ConfigValue;\n tableConfig: ConfigValue;\n fieldConfig: ConfigValue;\n id: string;\n };\n\n isExpanded: boolean;\n expand: (expand: boolean | ((isExpanded: boolean) => boolean)) => unknown;\n\n // name of the field in the form (may differ from the field apiId, ie. for localized fields)\n name: string;\n\n // current locale on localized field\n locale: string | undefined;\n\n // current entry id, null for new entries;\n entryId: string | null;\n\n isTableCell: boolean;\n\n isReadOnly: boolean | undefined;\n\n value: any;\n\n onBlur: (event?: FocusEvent) => Promise<void>;\n\n onChange: (event: InputEvent | any) => Promise<void>;\n\n onFocus: (event?: FocusEvent) => Promise<void>;\n\n // @see https://final-form.org/docs/react-final-form/types/FieldRenderProps\n meta: {\n active: boolean;\n error: any;\n touched: boolean;\n };\n\n form: Form;\n field: Field;\n model: Model;\n installation: AppInstallation;\n}\n"],"names":["ExtensionPermission","reservedExtensionProps","handleProps","props","transformedProps","Object","keys","forEach","key","includes","startsWith","replace","init","debug","_ref$onProps","onProps","givenUid","uid","Promise","resolve","reject","window","postMessage","error","message","URLSearchParams","location","search","get","console","info","zoid","create","tag","url","href","toString","autoResize","width","height","element","onConnected","type","xprops","then","status","onParentProps","_nevermind","resize","extensionProps","p","newExtensionProps","isExpanded","COMPLETED","DISABLED","PENDING","FieldRenderer","ListRenderer","TableRenderer","STRING","RICHTEXT","INT","FLOAT","BOOLEAN","JSON","DATETIME","DATE","LOCATION","COLOR","ENUMERATION","RELATION","ASSET","UNION"],"mappings":"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,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A,2BC9KoB,CACnCyC,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/app.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import type { ExtensionPropsBase } from './base';
2
+ import type { AppInstallation } from './type-helpers/appInstallation';
3
+ declare type UpdateInstallation = (arg: Partial<Pick<AppInstallation, 'config' | 'status'>>) => Promise<AppInstallation>;
4
+ export interface AppProps extends ExtensionPropsBase {
5
+ updateInstallation: UpdateInstallation;
6
+ installation: AppInstallation;
7
+ }
8
+ export {};
package/dist/base.d.ts ADDED
@@ -0,0 +1,56 @@
1
+ import type { ShowToast } from './type-helpers/toast';
2
+ import type { OpenDialog } from './type-helpers/dialog';
3
+ import type { OpenAssetPicker } from './type-helpers/openAssetPicker';
4
+ export declare const reservedExtensionProps: string[];
5
+ export declare enum ExtensionPermission {
6
+ INPUT = "INPUT",
7
+ FORM = "FORM",
8
+ API = "API"
9
+ }
10
+ declare type ConfigVariableName = string;
11
+ declare type ConfigVariableSettings = {
12
+ type: 'string' | 'number' | 'boolean';
13
+ displayName?: string;
14
+ description?: string;
15
+ required?: boolean;
16
+ defaultValue?: any;
17
+ };
18
+ export declare type ConfigFields = Record<ConfigVariableName, ConfigVariableSettings>;
19
+ export declare type ConfigValue = Record<string, boolean | number | string | undefined | null>;
20
+ export declare type FieldConfig = {
21
+ tableConfig: ConfigValue;
22
+ fieldConfig: ConfigValue;
23
+ };
24
+ export declare type FormSidebarConfig = {
25
+ sidebarConfig: ConfigValue;
26
+ };
27
+ export declare type Project = {
28
+ id: string;
29
+ name: string;
30
+ mgmtApi: string;
31
+ mgmtToken: string;
32
+ };
33
+ export declare type Environment = {
34
+ id: string;
35
+ name: string;
36
+ endpoint: string;
37
+ authToken: string;
38
+ };
39
+ export declare type Context = {
40
+ project: Project;
41
+ environment: Environment;
42
+ };
43
+ export interface ExtensionPropsBase {
44
+ context: Context;
45
+ openDialog: OpenDialog;
46
+ showToast: ShowToast;
47
+ openAssetPicker: OpenAssetPicker;
48
+ redirectParent: (location: string | Location) => Promise<void>;
49
+ historyReplace: (url: string | HistoryCallback) => Promise<void>;
50
+ historyPush: (url: string | HistoryCallback) => Promise<void>;
51
+ }
52
+ export interface ExtensionDialogProps extends ExtensionPropsBase {
53
+ onCloseDialog: (value: any) => void;
54
+ }
55
+ declare type HistoryCallback = (href: Location['href']) => string;
56
+ export {};
@@ -0,0 +1,54 @@
1
+ import type { Form } from './type-helpers/form';
2
+ import type { ExtensionPropsBase, ConfigValue } from './base';
3
+ import type { Model } from './type-helpers/model';
4
+ import type { AppInstallation } from './type-helpers/appInstallation';
5
+ import type { Field } from './type-helpers/field';
6
+ export declare const FieldExtensionType: {
7
+ readonly STRING: "STRING";
8
+ readonly RICHTEXT: "RICHTEXT";
9
+ readonly INT: "INT";
10
+ readonly FLOAT: "FLOAT";
11
+ readonly BOOLEAN: "BOOLEAN";
12
+ readonly JSON: "JSON";
13
+ readonly DATETIME: "DATETIME";
14
+ readonly DATE: "DATE";
15
+ readonly LOCATION: "LOCATION";
16
+ readonly COLOR: "COLOR";
17
+ readonly ENUMERATION: "ENUMERATION";
18
+ readonly RELATION: "RELATION";
19
+ readonly ASSET: "ASSET";
20
+ readonly UNION: "UNION";
21
+ };
22
+ export declare const FieldExtensionFeature: {
23
+ readonly FieldRenderer: "FieldRenderer";
24
+ readonly ListRenderer: "ListRenderer";
25
+ readonly TableRenderer: "TableRenderer";
26
+ };
27
+ export interface FieldExtensionProps extends ExtensionPropsBase {
28
+ extension: {
29
+ config: ConfigValue;
30
+ tableConfig: ConfigValue;
31
+ fieldConfig: ConfigValue;
32
+ id: string;
33
+ };
34
+ isExpanded: boolean;
35
+ expand: (expand: boolean | ((isExpanded: boolean) => boolean)) => unknown;
36
+ name: string;
37
+ locale: string | undefined;
38
+ entryId: string | null;
39
+ isTableCell: boolean;
40
+ isReadOnly: boolean | undefined;
41
+ value: any;
42
+ onBlur: (event?: FocusEvent) => Promise<void>;
43
+ onChange: (event: InputEvent | any) => Promise<void>;
44
+ onFocus: (event?: FocusEvent) => Promise<void>;
45
+ meta: {
46
+ active: boolean;
47
+ error: any;
48
+ touched: boolean;
49
+ };
50
+ form: Form;
51
+ field: Field;
52
+ model: Model;
53
+ installation: AppInstallation;
54
+ }
@@ -0,0 +1,27 @@
1
+ import type { ExtensionPropsBase, ConfigValue } from './base';
2
+ import type { Form } from './type-helpers/form';
3
+ import type { Locale, FormLocale } from './type-helpers/locale';
4
+ import type { Model } from './type-helpers/model';
5
+ import type { Stage } from './type-helpers/stage';
6
+ import type { User } from './type-helpers/user';
7
+ import type { AppInstallation } from './type-helpers/appInstallation';
8
+ export interface FormSidebarExtensionProps extends ExtensionPropsBase {
9
+ extension: {
10
+ config: ConfigValue;
11
+ sidebarConfig: ConfigValue;
12
+ id: string;
13
+ };
14
+ form: Form;
15
+ model: Model;
16
+ allLocales: Locale[];
17
+ selectedLocales: FormLocale[];
18
+ stages: Stage[];
19
+ entry: {
20
+ id: string | null;
21
+ createdBy?: User;
22
+ updatedBy?: User;
23
+ createdAt: Date | null;
24
+ updatedAt: Date | null;
25
+ } | null;
26
+ installation: AppInstallation;
27
+ }
@@ -0,0 +1,40 @@
1
+ import { ExtensionDialogProps } from './base';
2
+ export { ExtensionDialogProps, reservedExtensionProps } from './base';
3
+ import type { FieldExtensionProps } from './field';
4
+ import type { FormSidebarExtensionProps } from './formSidebar';
5
+ export * from './base';
6
+ export type { FormState, FieldState, FieldSubscription, Subscriber, FormSubscription, Form, } from './type-helpers/form';
7
+ export type { VisibilityTypes, SetFieldsVisibility, VisibilityMap, } from './type-helpers/visibility';
8
+ export type { FieldExtensionProps } from './field';
9
+ export type { AppProps } from './app';
10
+ export type { FormSidebarExtensionProps } from './formSidebar';
11
+ export { FieldExtensionFeature, FieldExtensionType } from './field';
12
+ export * from './type-helpers/appInstallation';
13
+ export declare type ExtensionProps = FieldExtensionProps | FormSidebarExtensionProps | ExtensionDialogProps;
14
+ declare type Xprops = {
15
+ onProps: (props: Record<string, any>) => void;
16
+ onConnected: (uid: string) => Promise<unknown>;
17
+ resize: (size: {
18
+ height: 'auto' | 'full' | number;
19
+ width: 'auto' | '100%' | number;
20
+ }) => unknown;
21
+ } & ExtensionProps;
22
+ declare global {
23
+ interface Window {
24
+ xprops: Xprops;
25
+ }
26
+ }
27
+ export declare function init({ debug, onProps, uid: givenUid, }: {
28
+ onProps: (props: any) => unknown;
29
+ debug?: boolean;
30
+ uid?: string;
31
+ }): Promise<{
32
+ status: 'ok';
33
+ props: any;
34
+ } | {
35
+ status: 'validation';
36
+ }>;
37
+ declare const _default: {
38
+ init: typeof init;
39
+ };
40
+ export default _default;
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+
2
+ 'use strict'
3
+
4
+ if (process.env.NODE_ENV === 'production') {
5
+ module.exports = require('./app-sdk.cjs.production.min.js')
6
+ } else {
7
+ module.exports = require('./app-sdk.cjs.development.js')
8
+ }
@@ -0,0 +1,11 @@
1
+ import type { ConfigValue } from '../base';
2
+ export declare const AppInstallationStatus: {
3
+ readonly COMPLETED: "COMPLETED";
4
+ readonly DISABLED: "DISABLED";
5
+ readonly PENDING: "PENDING";
6
+ };
7
+ export declare type AppInstallation = {
8
+ id: string;
9
+ config: ConfigValue;
10
+ status: keyof typeof AppInstallationStatus;
11
+ };
@@ -0,0 +1,5 @@
1
+ export declare type OpenDialog = <DialogReturn = any, DialogProps = Record<string, any>>(src: string, props?: {
2
+ disableOverlayClick?: boolean;
3
+ maxWidth?: string;
4
+ ariaLabel?: string;
5
+ } & DialogProps) => Promise<DialogReturn | null>;
@@ -0,0 +1,12 @@
1
+ import type { FieldExtensionType } from '../field';
2
+ export declare type Field = {
3
+ id: string;
4
+ apiId: string;
5
+ description: string | null;
6
+ displayName: string;
7
+ isList: boolean;
8
+ isLocalized: boolean;
9
+ isRequired: boolean;
10
+ isUnique: boolean;
11
+ type: keyof typeof FieldExtensionType;
12
+ };
@@ -0,0 +1,20 @@
1
+ import type { SetFieldsVisibility } from '..';
2
+ import type { FormSubscription, FormState, FieldState, FieldSubscription, FormSubscriber } from 'final-form';
3
+ export interface AnyObject {
4
+ [key: string]: any;
5
+ }
6
+ export interface ValidationErrors extends AnyObject {
7
+ }
8
+ export interface SubmissionErrors extends AnyObject {
9
+ }
10
+ export declare type Subscriber<V = Record<string, any>> = (value: V) => void;
11
+ export declare type Form = {
12
+ change: <Value = any>(name: string, value: Value) => Promise<void>;
13
+ getState: <Values = Record<string, any>>() => Promise<FormState<Values>>;
14
+ getFieldState: <Value = any>(fieldName: string) => Promise<FieldState<Value> | undefined>;
15
+ subscribeToFieldState: <Value = any>(name: string, callback: (state: FieldState<Value>) => any, subscription: FieldSubscription) => Promise<() => any>;
16
+ subscribeToFormState: <Values = Record<string, any>>(callback: FormSubscriber<Values>, subscription: FormSubscription) => Promise<() => any>;
17
+ setFieldsVisibility: SetFieldsVisibility;
18
+ changeBulk: (flatValues: Record<string, any>) => Promise<any>;
19
+ };
20
+ export { FormSubscription, FormState, FieldState, FieldSubscription, FormSubscriber, } from 'final-form';
@@ -0,0 +1,9 @@
1
+ export declare type Locale = {
2
+ apiId: string;
3
+ id: string;
4
+ displayName: string;
5
+ isDefault: boolean;
6
+ };
7
+ export declare type FormLocale = Locale & {
8
+ isEnabled: boolean;
9
+ };
@@ -0,0 +1,8 @@
1
+ export declare type Model = {
2
+ apiId: string;
3
+ apiIdPlural: string;
4
+ id: string;
5
+ description?: string | null | undefined;
6
+ displayName: string;
7
+ isLocalized: boolean;
8
+ };
@@ -0,0 +1,13 @@
1
+ export declare type OpenAssetPicker = () => Promise<null | (Asset & Record<string, unknown>)>;
2
+ export interface Asset {
3
+ createdAt: string;
4
+ fileName: string;
5
+ handle: string;
6
+ height?: number;
7
+ id: string;
8
+ mimeType?: string;
9
+ size?: number;
10
+ updatedAt: string;
11
+ url: string;
12
+ width?: number;
13
+ }
@@ -0,0 +1,12 @@
1
+ export declare type ColorPalette = 'PINK' | 'PURPLE' | 'ORANGE' | 'RED' | 'BROWN' | 'TEAL' | 'GREEN' | 'YELLOW';
2
+ export declare type Stage = {
3
+ id: string;
4
+ apiId: string;
5
+ color: string;
6
+ colorPaletteId: ColorPalette;
7
+ backgroundColor: string;
8
+ displayName: string;
9
+ description?: string | null | undefined;
10
+ isSystem: boolean;
11
+ position: number;
12
+ };
@@ -0,0 +1,14 @@
1
+ declare type Id = number | string;
2
+ export declare type VariantColor = 'success' | 'error' | 'warning' | 'info' | 'primary' | 'dark' | 'publish';
3
+ export declare type Position = 'top-right' | 'top-center' | 'top-left' | 'bottom-right' | 'bottom-center' | 'bottom-left';
4
+ declare type ToastOptions = {
5
+ title: string;
6
+ description?: string;
7
+ variantColor: VariantColor;
8
+ id?: Id;
9
+ isClosable?: boolean;
10
+ position?: Position;
11
+ duration?: number;
12
+ };
13
+ export declare type ShowToast = (options: ToastOptions) => Promise<Id>;
14
+ export {};
@@ -0,0 +1,8 @@
1
+ export declare type UserKind = 'MEMBER' | 'PAT' | 'PUBLIC' | 'WEBHOOK';
2
+ export declare type User = {
3
+ id: string;
4
+ kind: UserKind;
5
+ name: string;
6
+ picture: string | null;
7
+ isActive: boolean;
8
+ };
@@ -0,0 +1,5 @@
1
+ export declare type VisibilityTypes = 'READ_WRITE' | 'READ_ONLY' | 'HIDDEN';
2
+ export declare type VisibilityMap = {
3
+ [fieldApiId: string]: VisibilityTypes;
4
+ };
5
+ export declare type SetFieldsVisibility = (arg: VisibilityMap | ((currentVisibilityMap: VisibilityMap) => VisibilityMap)) => void;
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@hygraph/app-sdk",
3
+ "license": "MIT",
4
+ "version": "0.0.2",
5
+ "author": "Hygraph",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "main": "dist/index.js",
10
+ "module": "dist/app-sdk.esm.js",
11
+ "browser": "dist/app-sdk.umd.production.min.js",
12
+ "unpkg": "dist/app-sdk.umd.production.min.js",
13
+ "typings": "dist/index.d.ts",
14
+ "types": "dist/index.d.ts",
15
+ "scripts": {
16
+ "build": "tsdx build --format cjs,esm,umd",
17
+ "test": "echo \"Error: no test specified\" && exit 1",
18
+ "lint": "tsdx lint",
19
+ "prepare": "npm run build"
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "src"
24
+ ],
25
+ "prettier": {
26
+ "printWidth": 80,
27
+ "semi": true,
28
+ "singleQuote": true,
29
+ "trailingComma": "es5"
30
+ },
31
+ "dependencies": {
32
+ "@graphcms/zoid": "^9.0.64-alpha.3",
33
+ "final-form": "4.20.6"
34
+ },
35
+ "devDependencies": {
36
+ "tsdx": "^0.14.1",
37
+ "tslib": "^2.3.0",
38
+ "typescript": "^4.3.5"
39
+ },
40
+ "gitHead": "77d8975601e7f944471fede0c200ffd7779dda05"
41
+ }
package/src/app.ts ADDED
@@ -0,0 +1,11 @@
1
+ import type { ExtensionPropsBase } from './base';
2
+ import type { AppInstallation } from './type-helpers/appInstallation';
3
+
4
+ type UpdateInstallation = (
5
+ arg: Partial<Pick<AppInstallation, 'config' | 'status'>>
6
+ ) => Promise<AppInstallation>;
7
+
8
+ export interface AppProps extends ExtensionPropsBase {
9
+ updateInstallation: UpdateInstallation;
10
+ installation: AppInstallation;
11
+ }
package/src/base.ts ADDED
@@ -0,0 +1,93 @@
1
+ import type { ShowToast } from './type-helpers/toast';
2
+ import type { OpenDialog } from './type-helpers/dialog';
3
+ import type { OpenAssetPicker } from './type-helpers/openAssetPicker';
4
+
5
+ // see https://github.com/krakenjs/zoid/blob/master/src/component/props.js#L53
6
+ export const reservedExtensionProps = [
7
+ 'timeout',
8
+ 'window',
9
+ 'close',
10
+ 'focus',
11
+ 'resize',
12
+ 'uid',
13
+ 'cspNonce',
14
+ 'getParent',
15
+ 'getParentDomain',
16
+ 'hide',
17
+ 'show',
18
+ 'export',
19
+ 'onDisplay',
20
+ 'onRendered',
21
+ 'onRender',
22
+ 'onClose',
23
+ 'onDestroy',
24
+ 'onResize',
25
+ 'onFocus',
26
+ 'onError',
27
+ 'onProps',
28
+ ];
29
+
30
+ export enum ExtensionPermission {
31
+ INPUT = 'INPUT',
32
+ FORM = 'FORM',
33
+ API = 'API',
34
+ }
35
+
36
+ type ConfigVariableName = string;
37
+
38
+ type ConfigVariableSettings = {
39
+ type: 'string' | 'number' | 'boolean';
40
+ displayName?: string;
41
+ description?: string;
42
+ required?: boolean;
43
+ defaultValue?: any;
44
+ };
45
+
46
+ export type ConfigFields = Record<ConfigVariableName, ConfigVariableSettings>;
47
+
48
+ export type ConfigValue = Record<
49
+ string,
50
+ boolean | number | string | undefined | null
51
+ >;
52
+
53
+ export type FieldConfig = {
54
+ tableConfig: ConfigValue;
55
+ fieldConfig: ConfigValue;
56
+ };
57
+
58
+ export type FormSidebarConfig = { sidebarConfig: ConfigValue };
59
+
60
+ export type Project = {
61
+ id: string;
62
+ name: string;
63
+ mgmtApi: string;
64
+ mgmtToken: string;
65
+ };
66
+
67
+ export type Environment = {
68
+ id: string;
69
+ name: string;
70
+ endpoint: string;
71
+ authToken: string;
72
+ };
73
+
74
+ export type Context = {
75
+ project: Project;
76
+ environment: Environment;
77
+ };
78
+
79
+ export interface ExtensionPropsBase {
80
+ context: Context;
81
+ openDialog: OpenDialog;
82
+ showToast: ShowToast;
83
+ openAssetPicker: OpenAssetPicker;
84
+ redirectParent: (location: string | Location) => Promise<void>;
85
+ historyReplace: (url: string | HistoryCallback) => Promise<void>;
86
+ historyPush: (url: string | HistoryCallback) => Promise<void>;
87
+ }
88
+
89
+ export interface ExtensionDialogProps extends ExtensionPropsBase {
90
+ onCloseDialog: (value: any) => void;
91
+ }
92
+
93
+ type HistoryCallback = (href: Location['href']) => string;
@@ -0,0 +1,2 @@
1
+ declare module '@graphcms/zoid';
2
+ declare module '@graphcms/zoid/lib/zoid.js';
package/src/field.ts ADDED
@@ -0,0 +1,73 @@
1
+ import type { Form } from './type-helpers/form';
2
+ import type { ExtensionPropsBase, ConfigValue } from './base';
3
+ import type { Model } from './type-helpers/model';
4
+ import type { AppInstallation } from './type-helpers/appInstallation';
5
+ import type { Field } from './type-helpers/field';
6
+
7
+ export const FieldExtensionType = {
8
+ STRING: 'STRING',
9
+ RICHTEXT: 'RICHTEXT',
10
+ INT: 'INT',
11
+ FLOAT: 'FLOAT',
12
+ BOOLEAN: 'BOOLEAN',
13
+ JSON: 'JSON',
14
+ DATETIME: 'DATETIME',
15
+ DATE: 'DATE',
16
+ LOCATION: 'LOCATION',
17
+ COLOR: 'COLOR',
18
+ ENUMERATION: 'ENUMERATION',
19
+ RELATION: 'RELATION',
20
+ ASSET: 'ASSET',
21
+ UNION: 'UNION',
22
+ } as const;
23
+
24
+ export const FieldExtensionFeature = {
25
+ FieldRenderer: 'FieldRenderer',
26
+ ListRenderer: 'ListRenderer',
27
+ TableRenderer: 'TableRenderer',
28
+ } as const;
29
+
30
+ export interface FieldExtensionProps extends ExtensionPropsBase {
31
+ extension: {
32
+ config: ConfigValue;
33
+ tableConfig: ConfigValue;
34
+ fieldConfig: ConfigValue;
35
+ id: string;
36
+ };
37
+
38
+ isExpanded: boolean;
39
+ expand: (expand: boolean | ((isExpanded: boolean) => boolean)) => unknown;
40
+
41
+ // name of the field in the form (may differ from the field apiId, ie. for localized fields)
42
+ name: string;
43
+
44
+ // current locale on localized field
45
+ locale: string | undefined;
46
+
47
+ // current entry id, null for new entries;
48
+ entryId: string | null;
49
+
50
+ isTableCell: boolean;
51
+
52
+ isReadOnly: boolean | undefined;
53
+
54
+ value: any;
55
+
56
+ onBlur: (event?: FocusEvent) => Promise<void>;
57
+
58
+ onChange: (event: InputEvent | any) => Promise<void>;
59
+
60
+ onFocus: (event?: FocusEvent) => Promise<void>;
61
+
62
+ // @see https://final-form.org/docs/react-final-form/types/FieldRenderProps
63
+ meta: {
64
+ active: boolean;
65
+ error: any;
66
+ touched: boolean;
67
+ };
68
+
69
+ form: Form;
70
+ field: Field;
71
+ model: Model;
72
+ installation: AppInstallation;
73
+ }