{"version":3,"file":"document-configuration.context-DKcHlT2T.js","sources":["../../../src/packages/documents/documents/global-contexts/document-configuration.context.ts"],"sourcesContent":["import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';\r\nimport { UmbContextToken } from '@umbraco-cms/backoffice/context-api';\r\nimport type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';\r\nimport type { UmbApi } from '@umbraco-cms/backoffice/extension-api';\r\nimport { DocumentService, type DocumentConfigurationResponseModel } from '@umbraco-cms/backoffice/external/backend-api';\r\nimport { tryExecuteAndNotify } from '@umbraco-cms/backoffice/resources';\r\n\r\n// TODO: Turn this into a Repository with a Store that holds the cache [NL]\r\n/**\r\n * A context for fetching and caching the document configuration.\r\n * @deprecated Do not use this one, it will have ot change in near future.\r\n */\r\nexport class UmbDocumentConfigurationContext extends UmbControllerBase implements UmbApi {\r\n\t/**\r\n\t * The cached document configuration.\r\n\t */\r\n\tstatic #DocumentConfiguration: Promise;\r\n\r\n\tconstructor(host: UmbControllerHost) {\r\n\t\tsuper(host);\r\n\t\tthis.provideContext(UMB_DOCUMENT_CONFIGURATION_CONTEXT, this);\r\n\t}\r\n\r\n\t/**\r\n\t * Get the document configuration from the server, or return the cached configuration if it has already been fetched.\r\n\t * @returns A promise that resolves to the document configuration, or null if the configuration could not be fetched.\r\n\t */\r\n\tgetDocumentConfiguration(): Promise {\r\n\t\treturn (UmbDocumentConfigurationContext.#DocumentConfiguration ??= this.fetchDocumentConfiguration());\r\n\t}\r\n\r\n\t/**\r\n\t * Fetch the document configuration from the server.\r\n\t * @returns A promise that resolves to the document configuration, or null if the configuration could not be fetched.\r\n\t */\r\n\tasync fetchDocumentConfiguration() {\r\n\t\tconst { data } = await tryExecuteAndNotify(this, DocumentService.getDocumentConfiguration());\r\n\r\n\t\treturn data ?? null;\r\n\t}\r\n}\r\n\r\n// Export as default to work as a global context:\r\nexport default UmbDocumentConfigurationContext;\r\n\r\n/**\r\n * @deprecated Do not use this one, it will have ot change in near future.\r\n */\r\nexport const UMB_DOCUMENT_CONFIGURATION_CONTEXT = new UmbContextToken(\r\n\t'UmbDocumentConfigurationContext',\r\n);\r\n"],"names":["UmbDocumentConfigurationContext","UmbControllerBase","#DocumentConfiguration","host","UMB_DOCUMENT_CONFIGURATION_CONTEXT","data","tryExecuteAndNotify","DocumentService","UmbContextToken"],"mappings":";;;;AAYO,MAAMA,UAAwCC,EAAoC;AAAA;AAAA;AAAA;AAAA,EAIxF,OAAOC;AAAA,EAEP,YAAYC,GAAyB;AACpC,UAAMA,CAAI,GACL,KAAA,eAAeC,GAAoC,IAAI;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO7D,2BAA+E;AACtE,WAAAJ,EAAgCE,OAA2B,KAAK,2BAA2B;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOpG,MAAM,6BAA6B;AAC5B,UAAA,EAAE,MAAAG,MAAS,MAAMC,EAAoB,MAAMC,EAAgB,0BAA0B;AAE3F,WAAOF,KAAQ;AAAA,EAAA;AAEjB;AAQO,MAAMD,IAAqC,IAAII;AAAA,EACrD;AACD;"}