@openedx/frontend-base 1.0.0-alpha.14 → 1.0.0-alpha.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/runtime/config/index.js +5 -1
- package/dist/runtime/config/index.js.map +1 -1
- package/dist/runtime/index.d.ts +1 -1
- package/dist/runtime/index.js +1 -1
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/react/AuthenticatedPageRoute.d.ts +2 -0
- package/dist/runtime/react/AuthenticatedPageRoute.js +2 -0
- package/dist/runtime/react/AuthenticatedPageRoute.js.map +1 -1
- package/dist/runtime/react/NotFoundPage.d.ts +2 -0
- package/dist/runtime/react/NotFoundPage.js +14 -0
- package/dist/runtime/react/NotFoundPage.js.map +1 -0
- package/dist/runtime/react/index.d.ts +1 -0
- package/dist/runtime/react/index.js +1 -0
- package/dist/runtime/react/index.js.map +1 -1
- package/dist/runtime/routing/authenticatedLoader.d.ts +2 -0
- package/dist/runtime/routing/authenticatedLoader.js +27 -0
- package/dist/runtime/routing/authenticatedLoader.js.map +1 -0
- package/dist/runtime/routing/index.d.ts +1 -0
- package/dist/runtime/routing/index.js +1 -0
- package/dist/runtime/routing/index.js.map +1 -1
- package/dist/runtime/routing/utils.js +20 -5
- package/dist/runtime/routing/utils.js.map +1 -1
- package/dist/runtime/slots/widget/hooks.d.ts +3 -3
- package/dist/runtime/slots/widget/hooks.js.map +1 -1
- package/dist/runtime/slots/widget/types.d.ts +8 -0
- package/dist/runtime/slots/widget/types.js.map +1 -1
- package/dist/runtime/slots/widget/utils.d.ts +2 -2
- package/dist/runtime/slots/widget/utils.js +20 -2
- package/dist/runtime/slots/widget/utils.js.map +1 -1
- package/dist/shell/dev/devHome/HomePage.js +3 -3
- package/dist/shell/dev/devHome/HomePage.js.map +1 -1
- package/dist/shell/dev/slotShowcase/HorizontalSlotLayout.js +2 -1
- package/dist/shell/dev/slotShowcase/HorizontalSlotLayout.js.map +1 -1
- package/dist/shell/dev/slotShowcase/LayoutWithOptions.js +2 -2
- package/dist/shell/dev/slotShowcase/LayoutWithOptions.js.map +1 -1
- package/dist/shell/dev/slotShowcase/SlotShowcasePage.d.ts +1 -0
- package/dist/shell/dev/slotShowcase/SlotShowcasePage.js +10 -1
- package/dist/shell/dev/slotShowcase/SlotShowcasePage.js.map +1 -1
- package/dist/shell/dev/slotShowcase/ToggleByRoleLayout.d.ts +1 -0
- package/dist/shell/dev/slotShowcase/ToggleByRoleLayout.js +11 -0
- package/dist/shell/dev/slotShowcase/ToggleByRoleLayout.js.map +1 -0
- package/dist/shell/dev/slotShowcase/WidgetWithOptions.js +1 -1
- package/dist/shell/dev/slotShowcase/WidgetWithOptions.js.map +1 -1
- package/dist/shell/dev/slotShowcase/app.js +76 -40
- package/dist/shell/dev/slotShowcase/app.js.map +1 -1
- package/dist/shell/header/AuthenticatedMenu.js +0 -2
- package/dist/shell/header/AuthenticatedMenu.js.map +1 -1
- package/dist/shell/router/createRouter.js +12 -1
- package/dist/shell/router/createRouter.js.map +1 -1
- package/dist/tools/babel.config.d.ts +2 -0
- package/dist/tools/babel.config.js +3 -0
- package/dist/tools/cli/openedx.js +1 -1
- package/dist/tools/cli/utils/formatter.js +1 -8
- package/dist/tools/eslint/base.eslint.config.js +4 -3
- package/dist/tools/webpack/common-config/dev/getDevServer.js +1 -3
- package/dist/tools/webpack/plugins/html-webpack-new-relic-plugin/HtmlWebpackNewRelicPlugin.d.ts +1 -3
- package/dist/tools/webpack/utils/getPublicPath.js +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
|
@@ -254,7 +254,11 @@ export function addAppConfigs() {
|
|
|
254
254
|
publish(CONFIG_CHANGED);
|
|
255
255
|
}
|
|
256
256
|
export function getAppConfig(id) {
|
|
257
|
-
|
|
257
|
+
const { commonAppConfig } = getSiteConfig();
|
|
258
|
+
if (commonAppConfig === undefined) {
|
|
259
|
+
return appConfigs[id];
|
|
260
|
+
}
|
|
261
|
+
return merge({}, commonAppConfig, appConfigs[id]);
|
|
258
262
|
}
|
|
259
263
|
export function mergeAppConfig(id, newAppConfig) {
|
|
260
264
|
appConfigs[id] = merge(appConfigs[id], newAppConfig);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../runtime/config/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoGG;;;;;;;;;;;;AAEH,OAAO,KAAK,MAAM,cAAc,CAAC;AACjC,OAAO,KAAK,MAAM,cAAc,CAAC;AACjC,OAAO,EAEL,gBAAgB,EAEjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,IAAI,UAAU,GAAe;IAC3B,WAAW;IACX,MAAM,EAAE,EAAE;IACV,OAAO,EAAE,EAAE;IACX,QAAQ,EAAE,EAAE;IACZ,QAAQ,EAAE,EAAE;IACZ,SAAS,EAAE,EAAE;IACb,UAAU,EAAE,EAAE;IAEd,WAAW;IACX,WAAW,EAAE,gBAAgB,CAAC,UAAU;IACxC,IAAI,EAAE,EAAE;IACR,cAAc,EAAE,EAAE;IAClB,wBAAwB,EAAE,EAAE;IAC5B,oBAAoB,EAAE,IAAI;IAC1B,KAAK,EAAE,EAAE;IACT,qBAAqB,EAAE,+BAA+B;IACtD,gBAAgB,EAAE,oBAAoB;IACtC,iBAAiB,EAAE,IAAI;IACvB,4BAA4B,EAAE,6BAA6B;IAC3D,yBAAyB,EAAE,gBAAgB;IAC3C,kBAAkB,EAAE,eAAe;IACnC,UAAU,EAAE,IAAI;CACjB,CAAC;AAEF;;;;;;;;;;;;;;;IAeI;AACJ,MAAM,UAAU,aAAa;IAC3B,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,EAAE,CAAC;QAC3C,OAAO,GAAG,CAAC;IACb,CAAC;IAED,MAAM,kBAAkB,GAAG,MAAA,aAAa,EAAE,CAAC,wBAAwB,mCAAI,EAAE,CAAC;IAC1E,OAAO,MAAA,kBAAkB,CAAC,GAAG,CAAC,mCAAI,GAAG,CAAC;AACxC,CAAC","sourcesContent":["/**\n * #### Import members from **@edx/frontend-base**\n *\n * The configuration module provides utilities for working with an application's configuration\n * document (SiteConfig). Configuration variables can be supplied to the\n * application in three different ways. They are applied in the following order:\n *\n * - Site Configuration File (site.config.tsx)\n * - Initialization Config Handler\n * - Runtime Configuration\n *\n * Last one in wins, and are deep merged together. Variables with the same name defined via the\n * later methods will override any defined using an earlier method. i.e., if a variable is defined\n * in Runtime Configuration, that will override the same variable defined in either of the earlier\n * methods. Configuration defined in a JS file will override any default values below.\n *\n * ##### Site Configuration File\n *\n * Configuration variables can be supplied in a file named site.config.tsx. This file must\n * export either an Object containing configuration variables or a function. The function must\n * return an Object containing configuration variables or, alternately, a promise which resolves to\n * an Object.\n *\n * Using a function or async function allows the configuration to be resolved at runtime (because\n * the function will be executed at runtime). This is not common, and the capability is included\n * for the sake of flexibility.\n *\n * The Site Configuration File is well-suited to extensibility use cases or component overrides,\n * in that the configuration file can depend on any installed JavaScript module. It is also the\n * preferred way of doing build-time configuration if runtime configuration isn't used by your\n * deployment of the platform.\n *\n * Exporting a config object:\n * ```\n * const siteConfig = {\n * lmsBaseUrl: 'http://localhost:18000'\n * };\n *\n * export default siteConfig;\n * ```\n *\n * Exporting a function that returns an object:\n * ```\n * function getSiteConfig() {\n * return {\n * lmsBaseUrl: 'http://localhost:18000'\n * };\n * }\n * ```\n *\n * Exporting a function that returns a promise that resolves to an object:\n * ```\n * function getAsyncSiteConfig() {\n * return new Promise((resolve, reject) => {\n * resolve({\n * lmsBaseUrl: 'http://localhost:18000'\n * });\n * });\n * }\n *\n * export default getAsyncSiteConfig;\n * ```\n *\n * ##### Initialization Config Handler\n *\n * The configuration document can be extended by\n * applications at run-time using a `config` initialization handler. Please see the Initialization\n * documentation for more information on handlers and initialization phases.\n *\n * ```\n * initialize({\n * handlers: {\n * config: () => {\n * mergeSiteConfig({\n * CUSTOM_VARIABLE: 'custom value',\n * lmsBaseUrl: 'http://localhost:18001' // You can override variables, but this is uncommon.\n * }, 'App config override handler');\n * },\n * },\n * });\n * ```\n *\n * ##### Runtime Configuration\n *\n * Configuration variables can also be supplied using the \"runtime configuration\" method, taking\n * advantage of the Micro-frontend Config API in edx-platform. More information on this API can be\n * found in the ADR which introduced it:\n *\n * https://github.com/openedx/edx-platform/blob/master/lms/djangoapps/mfe_config_api/docs/decisions/0001-mfe-config-api.rst\n *\n * The runtime configuration method can be enabled by supplying a runtimeConfigJsonUrl via one of the other\n * two configuration methods above.\n *\n * Runtime configuration is particularly useful if you need to supply different configurations to\n * a single deployment of a micro-frontend, for instance. It is also a perfectly valid alternative\n * to build-time configuration, though it introduces an additional API call to edx-platform on MFE\n * initialization.\n *\n *\n * @module Config\n */\n\nimport keyBy from 'lodash.keyby';\nimport merge from 'lodash.merge';\nimport {\n AppConfig,\n EnvironmentTypes,\n SiteConfig\n} from '../../types';\nimport { ACTIVE_ROLES_CHANGED, CONFIG_CHANGED } from '../constants';\nimport { publish } from '../subscriptions';\n\nlet siteConfig: SiteConfig = {\n // Required\n siteId: '',\n baseUrl: '',\n siteName: '',\n loginUrl: '',\n logoutUrl: '',\n lmsBaseUrl: '',\n\n // Optional\n environment: EnvironmentTypes.PRODUCTION,\n apps: [],\n externalRoutes: [],\n externalLinkUrlOverrides: [],\n runtimeConfigJsonUrl: null,\n theme: {},\n accessTokenCookieName: 'edx-jwt-cookie-header-payload',\n csrfTokenApiPath: '/csrf/api/v1/token',\n ignoredErrorRegex: null,\n languagePreferenceCookieName: 'openedx-language-preference',\n refreshAccessTokenApiPath: '/login_refresh',\n userInfoCookieName: 'edx-user-info',\n segmentKey: null,\n};\n\n/**\n * Getter for the application configuration document. This is synchronous and merely returns a\n * reference to an existing object, and is thus safe to call as often as desired.\n *\n * Example:\n *\n * ```\n * import { getSiteConfig } from '@openedx/frontend-base';\n *\n * const {\n * lmsBaseUrl,\n * } = getSiteConfig();\n * ```\n *\n * @returns {SiteConfig}\n */\nexport function getSiteConfig() {\n return siteConfig;\n}\n\n/**\n * Replaces the existing SiteConfig. This is not commonly used, but can be helpful for tests.\n *\n * Example:\n *\n * ```\n * import { setSiteConfig } from '@openedx/frontend-base';\n *\n * setSiteConfig({\n * lmsBaseUrl, // This is overriding the ENTIRE document - this is not merged in!\n * });\n * ```\n *\n * @param newConfig A replacement SiteConfig which will completely override the current SiteConfig.\n */\nexport function setSiteConfig(newSiteConfig: SiteConfig) {\n siteConfig = newSiteConfig;\n publish(CONFIG_CHANGED);\n}\n\ninterface MergeSiteConfigOptions {\n limitAppMergeToConfig?: boolean,\n}\n\n/**\n * Merges additional configuration values into the site config returned by `getSiteConfig`. Will\n * override any values that exist with the same keys.\n *\n * ```\n * mergeSiteConfig({\n * NEW_KEY: 'new value',\n * OTHER_NEW_KEY: 'other new value',\n * });\n *\n * This function uses lodash.merge internally to merge configuration objects\n * which means they will be merged recursively. See https://lodash.com/docs/latest#merge for\n * documentation on the exact behavior.\n *\n * Apps are merged by appId rather than array index. By default, apps in the incoming config\n * that don't exist in the current config will be added.\n *\n * When `limitAppMergeToConfig` is true:\n * - All non-app parts of the config are still merged normally\n * - Only the `config` property of each existing app is merged\n * - Apps in the incoming config that don't exist in the current config are ignored\n *\n * @param {Object} newSiteConfig\n * @param {Object} options\n * @param {boolean} options.limitAppMergeToConfig - Limit app merging to only the config property of existing apps\n */\nexport function mergeSiteConfig(\n newSiteConfig: Partial<SiteConfig>,\n options: MergeSiteConfigOptions = {}\n) {\n const { limitAppMergeToConfig = false } = options;\n const { apps: newApps, ...restOfNewConfig } = newSiteConfig;\n\n // lodash merge the top-level (non-app) part\n siteConfig = merge(siteConfig, restOfNewConfig);\n\n // if we don't have new apps, we're done\n if (!newApps?.length) {\n publish(CONFIG_CHANGED);\n return;\n }\n\n // if we're doing a full merge, merge the objects\n if (!limitAppMergeToConfig) {\n siteConfig.apps = Object.values(merge(\n keyBy(siteConfig.apps || [], 'appId'),\n keyBy(newApps, 'appId')\n ));\n publish(CONFIG_CHANGED);\n return;\n }\n\n // we're doing a config-only merge, if we don't\n // have apps already, we can't update their configs\n if (!siteConfig.apps?.length) {\n publish(CONFIG_CHANGED);\n return;\n }\n\n // handle config-only merging\n const newAppsById = keyBy(newApps, 'appId');\n for (const app of siteConfig.apps) {\n const newApp = newAppsById[app.appId];\n if (newApp?.config) {\n app.config = merge(app.config, newApp.config);\n }\n }\n\n publish(CONFIG_CHANGED);\n}\n\nconst appConfigs: Record<string, AppConfig> = {};\n\n/**\n * addAppConfigs finds any AppConfig objects in the apps in SiteConfig and makes their config\n * available to be used by Apps via getAppConfig(appId) or useAppConfig() functions. This is\n * used at initialization time to process any AppConfigs bundled with the site.\n */\nexport function addAppConfigs() {\n const { apps } = getSiteConfig();\n if (!apps) return;\n\n for (const app of apps) {\n const { appId, config } = app;\n if (config !== undefined) {\n appConfigs[appId] = config;\n }\n }\n\n publish(CONFIG_CHANGED);\n}\n\nexport function getAppConfig(id: string) {\n return appConfigs[id];\n}\n\nexport function mergeAppConfig(id: string, newAppConfig: AppConfig) {\n appConfigs[id] = merge(appConfigs[id], newAppConfig);\n publish(CONFIG_CHANGED);\n}\n\nlet activeRouteRoles: string[] = [];\n\nexport function setActiveRouteRoles(roles: string[]) {\n activeRouteRoles = roles;\n publish(ACTIVE_ROLES_CHANGED);\n}\n\nexport function getActiveRouteRoles() {\n return activeRouteRoles;\n}\n\nconst activeWidgetRoles: Record<string, number> = {};\n\nexport function addActiveWidgetRole(role: string) {\n activeWidgetRoles[role] ??= 0;\n activeWidgetRoles[role] += 1;\n publish(ACTIVE_ROLES_CHANGED);\n}\n\nexport function removeActiveWidgetRole(role: string) {\n if (activeWidgetRoles[role] !== undefined) {\n activeWidgetRoles[role] -= 1;\n }\n if (activeWidgetRoles[role] < 1) {\n delete activeWidgetRoles[role];\n }\n publish(ACTIVE_ROLES_CHANGED);\n}\n\nexport function getActiveWidgetRoles() {\n return Object.entries(activeWidgetRoles)\n .filter(([, count]: [role: string, count: number]) => count !== undefined && count > 0)\n .map(([role]: [role: string, count: number]) => role);\n}\n\n// Gets all active roles from the route roles and widget roles.\nexport function getActiveRoles() {\n return [...getActiveRouteRoles(), ...getActiveWidgetRoles()];\n}\n\n/**\n * Get an external link URL based on the URL provided. If the passed in URL is overridden in the\n * `externalLinkUrlOverrides` object, it will return the overridden URL. Otherwise, it will return\n * the provided URL.\n *\n *\n * @param {string} url - The default URL.\n * @returns {string} - The external link URL. Defaults to the input URL if not found in the\n * `externalLinkUrlOverrides` object. If the input URL is invalid, '#' is returned.\n *\n * @example\n * import { getExternalLinkUrl } from '@openedx/frontend-base';\n *\n * <Hyperlink\n * destination={getExternalLinkUrl(data.helpLink)}\n * target=\"_blank\"\n * >\n */\nexport function getExternalLinkUrl(url: string): string {\n // Guard against whitespace-only strings\n if (typeof url !== 'string' || !url.trim()) {\n return '#';\n }\n\n const overriddenLinkUrls = getSiteConfig().externalLinkUrlOverrides ?? {};\n return overriddenLinkUrls[url] ?? url;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../runtime/config/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoGG;;;;;;;;;;;;AAEH,OAAO,KAAK,MAAM,cAAc,CAAC;AACjC,OAAO,KAAK,MAAM,cAAc,CAAC;AACjC,OAAO,EAEL,gBAAgB,EAEjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,IA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;QAC1C,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IACD,IAAI,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QAChC,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IACD,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,oBAAoB;IAClC,OAAO,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC;SACrC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAgC,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,IAAI,KAAK,GAAG,CAAC,CAAC;SACtF,GAAG,CAAC,CAAC,CAAC,IAAI,CAAgC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;AAC1D,CAAC;AAED,+DAA+D;AAC/D,MAAM,UAAU,cAAc;IAC5B,OAAO,CAAC,GAAG,mBAAmB,EAAE,EAAE,GAAG,oBAAoB,EAAE,CAAC,CAAC;AAC/D,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAW;;IAC5C,wCAAwC;IACxC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC;QAC3C,OAAO,GAAG,CAAC;IACb,CAAC;IAED,MAAM,kBAAkB,GAAG,MAAA,aAAa,EAAE,CAAC,wBAAwB,mCAAI,EAAE,CAAC;IAC1E,OAAO,MAAA,kBAAkB,CAAC,GAAG,CAAC,mCAAI,GAAG,CAAC;AACxC,CAAC","sourcesContent":["/**\n * #### Import members from **@edx/frontend-base**\n *\n * The configuration module provides utilities for working with an application's configuration\n * document (SiteConfig). Configuration variables can be supplied to the\n * application in three different ways. They are applied in the following order:\n *\n * - Site Configuration File (site.config.tsx)\n * - Initialization Config Handler\n * - Runtime Configuration\n *\n * Last one in wins, and are deep merged together. Variables with the same name defined via the\n * later methods will override any defined using an earlier method. i.e., if a variable is defined\n * in Runtime Configuration, that will override the same variable defined in either of the earlier\n * methods. Configuration defined in a JS file will override any default values below.\n *\n * ##### Site Configuration File\n *\n * Configuration variables can be supplied in a file named site.config.tsx. This file must\n * export either an Object containing configuration variables or a function. The function must\n * return an Object containing configuration variables or, alternately, a promise which resolves to\n * an Object.\n *\n * Using a function or async function allows the configuration to be resolved at runtime (because\n * the function will be executed at runtime). This is not common, and the capability is included\n * for the sake of flexibility.\n *\n * The Site Configuration File is well-suited to extensibility use cases or component overrides,\n * in that the configuration file can depend on any installed JavaScript module. It is also the\n * preferred way of doing build-time configuration if runtime configuration isn't used by your\n * deployment of the platform.\n *\n * Exporting a config object:\n * ```\n * const siteConfig = {\n * lmsBaseUrl: 'http://localhost:18000'\n * };\n *\n * export default siteConfig;\n * ```\n *\n * Exporting a function that returns an object:\n * ```\n * function getSiteConfig() {\n * return {\n * lmsBaseUrl: 'http://localhost:18000'\n * };\n * }\n * ```\n *\n * Exporting a function that returns a promise that resolves to an object:\n * ```\n * function getAsyncSiteConfig() {\n * return new Promise((resolve, reject) => {\n * resolve({\n * lmsBaseUrl: 'http://localhost:18000'\n * });\n * });\n * }\n *\n * export default getAsyncSiteConfig;\n * ```\n *\n * ##### Initialization Config Handler\n *\n * The configuration document can be extended by\n * applications at run-time using a `config` initialization handler. Please see the Initialization\n * documentation for more information on handlers and initialization phases.\n *\n * ```\n * initialize({\n * handlers: {\n * config: () => {\n * mergeSiteConfig({\n * CUSTOM_VARIABLE: 'custom value',\n * lmsBaseUrl: 'http://localhost:18001' // You can override variables, but this is uncommon.\n * }, 'App config override handler');\n * },\n * },\n * });\n * ```\n *\n * ##### Runtime Configuration\n *\n * Configuration variables can also be supplied using the \"runtime configuration\" method, taking\n * advantage of the Micro-frontend Config API in edx-platform. More information on this API can be\n * found in the ADR which introduced it:\n *\n * https://github.com/openedx/edx-platform/blob/master/lms/djangoapps/mfe_config_api/docs/decisions/0001-mfe-config-api.rst\n *\n * The runtime configuration method can be enabled by supplying a runtimeConfigJsonUrl via one of the other\n * two configuration methods above.\n *\n * Runtime configuration is particularly useful if you need to supply different configurations to\n * a single deployment of a micro-frontend, for instance. It is also a perfectly valid alternative\n * to build-time configuration, though it introduces an additional API call to edx-platform on MFE\n * initialization.\n *\n *\n * @module Config\n */\n\nimport keyBy from 'lodash.keyby';\nimport merge from 'lodash.merge';\nimport {\n AppConfig,\n EnvironmentTypes,\n SiteConfig\n} from '../../types';\nimport { ACTIVE_ROLES_CHANGED, CONFIG_CHANGED } from '../constants';\nimport { publish } from '../subscriptions';\n\nlet siteConfig: SiteConfig = {\n // Required\n siteId: '',\n baseUrl: '',\n siteName: '',\n loginUrl: '',\n logoutUrl: '',\n lmsBaseUrl: '',\n\n // Optional\n environment: EnvironmentTypes.PRODUCTION,\n apps: [],\n externalRoutes: [],\n externalLinkUrlOverrides: [],\n runtimeConfigJsonUrl: null,\n theme: {},\n accessTokenCookieName: 'edx-jwt-cookie-header-payload',\n csrfTokenApiPath: '/csrf/api/v1/token',\n ignoredErrorRegex: null,\n languagePreferenceCookieName: 'openedx-language-preference',\n refreshAccessTokenApiPath: '/login_refresh',\n userInfoCookieName: 'edx-user-info',\n segmentKey: null,\n};\n\n/**\n * Getter for the application configuration document. This is synchronous and merely returns a\n * reference to an existing object, and is thus safe to call as often as desired.\n *\n * Example:\n *\n * ```\n * import { getSiteConfig } from '@openedx/frontend-base';\n *\n * const {\n * lmsBaseUrl,\n * } = getSiteConfig();\n * ```\n *\n * @returns {SiteConfig}\n */\nexport function getSiteConfig() {\n return siteConfig;\n}\n\n/**\n * Replaces the existing SiteConfig. This is not commonly used, but can be helpful for tests.\n *\n * Example:\n *\n * ```\n * import { setSiteConfig } from '@openedx/frontend-base';\n *\n * setSiteConfig({\n * lmsBaseUrl, // This is overriding the ENTIRE document - this is not merged in!\n * });\n * ```\n *\n * @param newConfig A replacement SiteConfig which will completely override the current SiteConfig.\n */\nexport function setSiteConfig(newSiteConfig: SiteConfig) {\n siteConfig = newSiteConfig;\n publish(CONFIG_CHANGED);\n}\n\ninterface MergeSiteConfigOptions {\n limitAppMergeToConfig?: boolean,\n}\n\n/**\n * Merges additional configuration values into the site config returned by `getSiteConfig`. Will\n * override any values that exist with the same keys.\n *\n * ```\n * mergeSiteConfig({\n * NEW_KEY: 'new value',\n * OTHER_NEW_KEY: 'other new value',\n * });\n *\n * This function uses lodash.merge internally to merge configuration objects\n * which means they will be merged recursively. See https://lodash.com/docs/latest#merge for\n * documentation on the exact behavior.\n *\n * Apps are merged by appId rather than array index. By default, apps in the incoming config\n * that don't exist in the current config will be added.\n *\n * When `limitAppMergeToConfig` is true:\n * - All non-app parts of the config are still merged normally\n * - Only the `config` property of each existing app is merged\n * - Apps in the incoming config that don't exist in the current config are ignored\n *\n * @param {Object} newSiteConfig\n * @param {Object} options\n * @param {boolean} options.limitAppMergeToConfig - Limit app merging to only the config property of existing apps\n */\nexport function mergeSiteConfig(\n newSiteConfig: Partial<SiteConfig>,\n options: MergeSiteConfigOptions = {}\n) {\n const { limitAppMergeToConfig = false } = options;\n const { apps: newApps, ...restOfNewConfig } = newSiteConfig;\n\n // lodash merge the top-level (non-app) part\n siteConfig = merge(siteConfig, restOfNewConfig);\n\n // if we don't have new apps, we're done\n if (!newApps?.length) {\n publish(CONFIG_CHANGED);\n return;\n }\n\n // if we're doing a full merge, merge the objects\n if (!limitAppMergeToConfig) {\n siteConfig.apps = Object.values(merge(\n keyBy(siteConfig.apps || [], 'appId'),\n keyBy(newApps, 'appId')\n ));\n publish(CONFIG_CHANGED);\n return;\n }\n\n // we're doing a config-only merge, if we don't\n // have apps already, we can't update their configs\n if (!siteConfig.apps?.length) {\n publish(CONFIG_CHANGED);\n return;\n }\n\n // handle config-only merging\n const newAppsById = keyBy(newApps, 'appId');\n for (const app of siteConfig.apps) {\n const newApp = newAppsById[app.appId];\n if (newApp?.config) {\n app.config = merge(app.config, newApp.config);\n }\n }\n\n publish(CONFIG_CHANGED);\n}\n\nconst appConfigs: Record<string, AppConfig> = {};\n\n/**\n * addAppConfigs finds any AppConfig objects in the apps in SiteConfig and makes their config\n * available to be used by Apps via getAppConfig(appId) or useAppConfig() functions. This is\n * used at initialization time to process any AppConfigs bundled with the site.\n */\nexport function addAppConfigs() {\n const { apps } = getSiteConfig();\n if (!apps) return;\n\n for (const app of apps) {\n const { appId, config } = app;\n if (config !== undefined) {\n appConfigs[appId] = config;\n }\n }\n\n publish(CONFIG_CHANGED);\n}\n\nexport function getAppConfig(id: string) {\n const { commonAppConfig } = getSiteConfig();\n if (commonAppConfig === undefined) {\n return appConfigs[id];\n }\n return merge({}, commonAppConfig, appConfigs[id]);\n}\n\nexport function mergeAppConfig(id: string, newAppConfig: AppConfig) {\n appConfigs[id] = merge(appConfigs[id], newAppConfig);\n publish(CONFIG_CHANGED);\n}\n\nlet activeRouteRoles: string[] = [];\n\nexport function setActiveRouteRoles(roles: string[]) {\n activeRouteRoles = roles;\n publish(ACTIVE_ROLES_CHANGED);\n}\n\nexport function getActiveRouteRoles() {\n return activeRouteRoles;\n}\n\nconst activeWidgetRoles: Record<string, number> = {};\n\nexport function addActiveWidgetRole(role: string) {\n activeWidgetRoles[role] ??= 0;\n activeWidgetRoles[role] += 1;\n publish(ACTIVE_ROLES_CHANGED);\n}\n\nexport function removeActiveWidgetRole(role: string) {\n if (activeWidgetRoles[role] !== undefined) {\n activeWidgetRoles[role] -= 1;\n }\n if (activeWidgetRoles[role] < 1) {\n delete activeWidgetRoles[role];\n }\n publish(ACTIVE_ROLES_CHANGED);\n}\n\nexport function getActiveWidgetRoles() {\n return Object.entries(activeWidgetRoles)\n .filter(([, count]: [role: string, count: number]) => count !== undefined && count > 0)\n .map(([role]: [role: string, count: number]) => role);\n}\n\n// Gets all active roles from the route roles and widget roles.\nexport function getActiveRoles() {\n return [...getActiveRouteRoles(), ...getActiveWidgetRoles()];\n}\n\n/**\n * Get an external link URL based on the URL provided. If the passed in URL is overridden in the\n * `externalLinkUrlOverrides` object, it will return the overridden URL. Otherwise, it will return\n * the provided URL.\n *\n *\n * @param {string} url - The default URL.\n * @returns {string} - The external link URL. Defaults to the input URL if not found in the\n * `externalLinkUrlOverrides` object. If the input URL is invalid, '#' is returned.\n *\n * @example\n * import { getExternalLinkUrl } from '@openedx/frontend-base';\n *\n * <Hyperlink\n * destination={getExternalLinkUrl(data.helpLink)}\n * target=\"_blank\"\n * >\n */\nexport function getExternalLinkUrl(url: string): string {\n // Guard against whitespace-only strings\n if (typeof url !== 'string' || !url.trim()) {\n return '#';\n }\n\n const overriddenLinkUrls = getSiteConfig().externalLinkUrlOverrides ?? {};\n return overriddenLinkUrls[url] ?? url;\n}\n"]}
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export { configureI18n, createIntl, defineMessages, FormattedDate, FormattedMess
|
|
|
6
6
|
export { auth, getBasename, initError, initialize } from './initialize';
|
|
7
7
|
export { configureLogging, getLoggingService, logError, logInfo, MockLoggingService, NewRelicLoggingService, resetLoggingService } from './logging';
|
|
8
8
|
export { CurrentAppContext, CurrentAppProvider, SiteContext, SiteProvider, AuthenticatedPageRoute, Divider, ErrorBoundary, ErrorPage, LoginRedirect, PageWrap, useSiteEvent, useAuthenticatedUser, useSiteConfig, useAppConfig } from './react';
|
|
9
|
-
export { getUrlByRouteRole, isRoleRouteObject } from './routing';
|
|
9
|
+
export { authenticatedLoader, getUrlByRouteRole, isRoleRouteObject } from './routing';
|
|
10
10
|
export { clearAllSubscriptions, publish, subscribe, unsubscribe } from './subscriptions';
|
|
11
11
|
export { initializeMockApp, mockMessages } from './testing';
|
|
12
12
|
export { camelCaseObject, convertKeyNames, getQueryParameters, isValidVariableName, modifyObjectKeys, snakeCaseObject } from './utils';
|
package/dist/runtime/index.js
CHANGED
|
@@ -6,7 +6,7 @@ export { configureI18n, createIntl, defineMessages, FormattedDate, FormattedMess
|
|
|
6
6
|
export { auth, getBasename, initError, initialize } from './initialize';
|
|
7
7
|
export { configureLogging, getLoggingService, logError, logInfo, MockLoggingService, NewRelicLoggingService, resetLoggingService } from './logging';
|
|
8
8
|
export { CurrentAppContext, CurrentAppProvider, SiteContext, SiteProvider, AuthenticatedPageRoute, Divider, ErrorBoundary, ErrorPage, LoginRedirect, PageWrap, useSiteEvent, useAuthenticatedUser, useSiteConfig, useAppConfig } from './react';
|
|
9
|
-
export { getUrlByRouteRole, isRoleRouteObject } from './routing';
|
|
9
|
+
export { authenticatedLoader, getUrlByRouteRole, isRoleRouteObject } from './routing';
|
|
10
10
|
export { clearAllSubscriptions, publish, subscribe, unsubscribe } from './subscriptions';
|
|
11
11
|
export { initializeMockApp, mockMessages } from './testing';
|
|
12
12
|
export { camelCaseObject, convertKeyNames, getQueryParameters, isValidVariableName, modifyObjectKeys, snakeCaseObject } from './utils';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../runtime/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,yBAAyB,EACzB,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EACvB,aAAa,EACb,cAAc,EACd,oBAAoB,EACrB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,0BAA0B,EAC1B,wBAAwB,EACxB,mBAAmB,EACnB,aAAa,EACb,uBAAuB,EACvB,sBAAsB,EACtB,0BAA0B,EAC1B,oBAAoB,EACpB,cAAc,EACd,aAAa,EACb,mBAAmB,EACnB,oBAAoB,EACpB,wBAAwB,EACxB,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACrB,MAAM,QAAQ,CAAC;AAEhB,OAAO,EACL,aAAa,EACb,aAAa,EACb,eAAe,EACf,aAAa,EACb,YAAY,EACZ,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,EACpB,cAAc,EACd,kBAAkB,EACnB,MAAM,UAAU,CAAC;AAElB,cAAc,aAAa,CAAC;AAE5B,OAAO,EACL,aAAa,EACb,UAAU,EACV,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,qBAAqB,EACrB,aAAa,EACb,SAAS,EACT,wBAAwB,EACxB,WAAW,EACX,wBAAwB,EACxB,wBAAwB,EACxB,SAAS,EACT,UAAU,EACV,YAAY,EACZ,SAAS,EACT,KAAK,EACL,cAAc,EACd,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,OAAO,EACR,MAAM,QAAQ,CAAC;AAEhB,OAAO,EACL,IAAI,EACJ,WAAW,EACX,SAAS,EACT,UAAU,EACX,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,QAAQ,EACR,OAAO,EACP,kBAAkB,EAClB,sBAAsB,EACtB,mBAAmB,EACpB,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,EACX,YAAY,EACZ,sBAAsB,EACtB,OAAO,EACP,aAAa,EACb,SAAS,EACT,aAAa,EACb,QAAQ,EACR,YAAY,EACZ,oBAAoB,EACpB,aAAa,EACb,YAAY,EACb,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,qBAAqB,EACrB,OAAO,EACP,SAAS,EACT,WAAW,EACZ,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,iBAAiB,EACjB,YAAY,EACb,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,eAAe,EAChB,MAAM,SAAS,CAAC;AAEjB,cAAc,SAAS,CAAC","sourcesContent":["export {\n configureAnalytics,\n getAnalyticsService,\n identifyAnonymousUser,\n identifyAuthenticatedUser,\n MockAnalyticsService,\n resetAnalyticsService,\n SegmentAnalyticsService,\n sendPageEvent,\n sendTrackEvent,\n sendTrackingLogEvent\n} from './analytics';\n\nexport {\n AUTHENTICATED_USER_CHANGED,\n AUTHENTICATED_USER_TOPIC,\n AxiosJwtAuthService,\n configureAuth,\n ensureAuthenticatedUser,\n fetchAuthenticatedUser,\n getAuthenticatedHttpClient,\n getAuthenticatedUser,\n getAuthService,\n getHttpClient,\n getLoginRedirectUrl,\n getLogoutRedirectUrl,\n hydrateAuthenticatedUser,\n MockAuthService,\n redirectToLogin,\n redirectToLogout,\n setAuthenticatedUser\n} from './auth';\n\nexport {\n getSiteConfig,\n setSiteConfig,\n mergeSiteConfig,\n addAppConfigs,\n getAppConfig,\n mergeAppConfig,\n setActiveRouteRoles,\n getActiveRouteRoles,\n addActiveWidgetRole,\n removeActiveWidgetRole,\n getActiveWidgetRoles,\n getActiveRoles,\n getExternalLinkUrl\n} from './config';\n\nexport * from './constants';\n\nexport {\n configureI18n,\n createIntl,\n defineMessages,\n FormattedDate,\n FormattedMessage,\n FormattedNumber,\n FormattedPlural,\n FormattedRelativeTime,\n FormattedTime,\n getLocale,\n getLocalizedLanguageName,\n getMessages,\n getPrimaryLanguageSubtag,\n getSupportedLanguageList,\n handleRtl,\n injectIntl,\n IntlProvider,\n intlShape,\n isRtl,\n LOCALE_CHANGED,\n LOCALE_TOPIC,\n mergeMessages,\n updateLocale,\n useIntl\n} from './i18n';\n\nexport {\n auth,\n getBasename,\n initError,\n initialize\n} from './initialize';\n\nexport {\n configureLogging,\n getLoggingService,\n logError,\n logInfo,\n MockLoggingService,\n NewRelicLoggingService,\n resetLoggingService\n} from './logging';\n\nexport {\n CurrentAppContext,\n CurrentAppProvider,\n SiteContext,\n SiteProvider,\n AuthenticatedPageRoute,\n Divider,\n ErrorBoundary,\n ErrorPage,\n LoginRedirect,\n PageWrap,\n useSiteEvent,\n useAuthenticatedUser,\n useSiteConfig,\n useAppConfig\n} from './react';\n\nexport {\n getUrlByRouteRole,\n isRoleRouteObject\n} from './routing';\n\nexport {\n clearAllSubscriptions,\n publish,\n subscribe,\n unsubscribe\n} from './subscriptions';\n\nexport {\n initializeMockApp,\n mockMessages\n} from './testing';\n\nexport {\n camelCaseObject,\n convertKeyNames,\n getQueryParameters,\n isValidVariableName,\n modifyObjectKeys,\n snakeCaseObject\n} from './utils';\n\nexport * from './slots';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../runtime/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,yBAAyB,EACzB,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EACvB,aAAa,EACb,cAAc,EACd,oBAAoB,EACrB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,0BAA0B,EAC1B,wBAAwB,EACxB,mBAAmB,EACnB,aAAa,EACb,uBAAuB,EACvB,sBAAsB,EACtB,0BAA0B,EAC1B,oBAAoB,EACpB,cAAc,EACd,aAAa,EACb,mBAAmB,EACnB,oBAAoB,EACpB,wBAAwB,EACxB,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACrB,MAAM,QAAQ,CAAC;AAEhB,OAAO,EACL,aAAa,EACb,aAAa,EACb,eAAe,EACf,aAAa,EACb,YAAY,EACZ,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,EACpB,cAAc,EACd,kBAAkB,EACnB,MAAM,UAAU,CAAC;AAElB,cAAc,aAAa,CAAC;AAE5B,OAAO,EACL,aAAa,EACb,UAAU,EACV,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,qBAAqB,EACrB,aAAa,EACb,SAAS,EACT,wBAAwB,EACxB,WAAW,EACX,wBAAwB,EACxB,wBAAwB,EACxB,SAAS,EACT,UAAU,EACV,YAAY,EACZ,SAAS,EACT,KAAK,EACL,cAAc,EACd,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,OAAO,EACR,MAAM,QAAQ,CAAC;AAEhB,OAAO,EACL,IAAI,EACJ,WAAW,EACX,SAAS,EACT,UAAU,EACX,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,QAAQ,EACR,OAAO,EACP,kBAAkB,EAClB,sBAAsB,EACtB,mBAAmB,EACpB,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,EACX,YAAY,EACZ,sBAAsB,EACtB,OAAO,EACP,aAAa,EACb,SAAS,EACT,aAAa,EACb,QAAQ,EACR,YAAY,EACZ,oBAAoB,EACpB,aAAa,EACb,YAAY,EACb,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,qBAAqB,EACrB,OAAO,EACP,SAAS,EACT,WAAW,EACZ,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,iBAAiB,EACjB,YAAY,EACb,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,eAAe,EAChB,MAAM,SAAS,CAAC;AAEjB,cAAc,SAAS,CAAC","sourcesContent":["export {\n configureAnalytics,\n getAnalyticsService,\n identifyAnonymousUser,\n identifyAuthenticatedUser,\n MockAnalyticsService,\n resetAnalyticsService,\n SegmentAnalyticsService,\n sendPageEvent,\n sendTrackEvent,\n sendTrackingLogEvent\n} from './analytics';\n\nexport {\n AUTHENTICATED_USER_CHANGED,\n AUTHENTICATED_USER_TOPIC,\n AxiosJwtAuthService,\n configureAuth,\n ensureAuthenticatedUser,\n fetchAuthenticatedUser,\n getAuthenticatedHttpClient,\n getAuthenticatedUser,\n getAuthService,\n getHttpClient,\n getLoginRedirectUrl,\n getLogoutRedirectUrl,\n hydrateAuthenticatedUser,\n MockAuthService,\n redirectToLogin,\n redirectToLogout,\n setAuthenticatedUser\n} from './auth';\n\nexport {\n getSiteConfig,\n setSiteConfig,\n mergeSiteConfig,\n addAppConfigs,\n getAppConfig,\n mergeAppConfig,\n setActiveRouteRoles,\n getActiveRouteRoles,\n addActiveWidgetRole,\n removeActiveWidgetRole,\n getActiveWidgetRoles,\n getActiveRoles,\n getExternalLinkUrl\n} from './config';\n\nexport * from './constants';\n\nexport {\n configureI18n,\n createIntl,\n defineMessages,\n FormattedDate,\n FormattedMessage,\n FormattedNumber,\n FormattedPlural,\n FormattedRelativeTime,\n FormattedTime,\n getLocale,\n getLocalizedLanguageName,\n getMessages,\n getPrimaryLanguageSubtag,\n getSupportedLanguageList,\n handleRtl,\n injectIntl,\n IntlProvider,\n intlShape,\n isRtl,\n LOCALE_CHANGED,\n LOCALE_TOPIC,\n mergeMessages,\n updateLocale,\n useIntl\n} from './i18n';\n\nexport {\n auth,\n getBasename,\n initError,\n initialize\n} from './initialize';\n\nexport {\n configureLogging,\n getLoggingService,\n logError,\n logInfo,\n MockLoggingService,\n NewRelicLoggingService,\n resetLoggingService\n} from './logging';\n\nexport {\n CurrentAppContext,\n CurrentAppProvider,\n SiteContext,\n SiteProvider,\n AuthenticatedPageRoute,\n Divider,\n ErrorBoundary,\n ErrorPage,\n LoginRedirect,\n PageWrap,\n useSiteEvent,\n useAuthenticatedUser,\n useSiteConfig,\n useAppConfig\n} from './react';\n\nexport {\n authenticatedLoader,\n getUrlByRouteRole,\n isRoleRouteObject\n} from './routing';\n\nexport {\n clearAllSubscriptions,\n publish,\n subscribe,\n unsubscribe\n} from './subscriptions';\n\nexport {\n initializeMockApp,\n mockMessages\n} from './testing';\n\nexport {\n camelCaseObject,\n convertKeyNames,\n getQueryParameters,\n isValidVariableName,\n modifyObjectKeys,\n snakeCaseObject\n} from './utils';\n\nexport * from './slots';\n"]}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* @deprecated Use authenticatedLoader instead.
|
|
3
|
+
*
|
|
2
4
|
* A react-router route that redirects to the login page when the route becomes active and the user
|
|
3
5
|
* is not authenticated. If the application has been initialized with `requireAuthenticatedUser`
|
|
4
6
|
* false, an authenticatedPageRoute can be used to protect a subset of the application's routes,
|
|
@@ -4,6 +4,8 @@ import { getLoginRedirectUrl } from '../auth';
|
|
|
4
4
|
import PageWrap from './PageWrap';
|
|
5
5
|
import { useAuthenticatedUser } from './hooks';
|
|
6
6
|
/**
|
|
7
|
+
* @deprecated Use authenticatedLoader instead.
|
|
8
|
+
*
|
|
7
9
|
* A react-router route that redirects to the login page when the route becomes active and the user
|
|
8
10
|
* is not authenticated. If the application has been initialized with `requireAuthenticatedUser`
|
|
9
11
|
* false, an authenticatedPageRoute can be used to protect a subset of the application's routes,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthenticatedPageRoute.js","sourceRoot":"","sources":["../../../runtime/react/AuthenticatedPageRoute.jsx"],"names":[],"mappings":";AAAA,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,QAAQ,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAE/C
|
|
1
|
+
{"version":3,"file":"AuthenticatedPageRoute.js","sourceRoot":"","sources":["../../../runtime/react/AuthenticatedPageRoute.jsx"],"names":[],"mappings":";AAAA,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,QAAQ,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAE/C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAAC,EAAE,WAAW,GAAG,IAAI,EAAE,QAAQ,EAAE;IAC7E,MAAM,iBAAiB,GAAG,oBAAoB,EAAE,CAAC;IACjD,IAAI,iBAAiB,KAAK,IAAI,EAAE,CAAC;QAC/B,MAAM,WAAW,GAAG,WAAW,IAAI,mBAAmB,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC7E,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;QAEpC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,CACL,KAAC,QAAQ,cACN,QAAQ,GACA,CACZ,CAAC;AACJ,CAAC;AAED,sBAAsB,CAAC,SAAS,GAAG;IACjC,WAAW,EAAE,SAAS,CAAC,MAAM;IAC7B,QAAQ,EAAE,SAAS,CAAC,IAAI,CAAC,UAAU;CACpC,CAAC","sourcesContent":["import PropTypes from 'prop-types';\n\nimport { getLoginRedirectUrl } from '../auth';\nimport PageWrap from './PageWrap';\nimport { useAuthenticatedUser } from './hooks';\n\n/**\n * @deprecated Use authenticatedLoader instead.\n * \n * A react-router route that redirects to the login page when the route becomes active and the user\n * is not authenticated. If the application has been initialized with `requireAuthenticatedUser`\n * false, an authenticatedPageRoute can be used to protect a subset of the application's routes,\n * rather than the entire application.\n *\n * It can optionally accept an override URL to redirect to instead of the login page.\n *\n * Like a `PageWrap`, also calls `sendPageEvent` when the route becomes active.\n *\n * @see PageWrap\n * @see {@link module:frontend-base~sendPageEvent}\n * @memberof module:React\n * @param {Object} props\n * @param {string} props.redirectUrl The URL anonymous users should be redirected to, rather than\n * viewing the route's contents.\n */\nexport default function AuthenticatedPageRoute({ redirectUrl = null, children }) {\n const authenticatedUser = useAuthenticatedUser();\n if (authenticatedUser === null) {\n const destination = redirectUrl || getLoginRedirectUrl(global.location.href);\n global.location.assign(destination);\n\n return null;\n }\n\n return (\n <PageWrap>\n {children}\n </PageWrap>\n );\n}\n\nAuthenticatedPageRoute.propTypes = {\n redirectUrl: PropTypes.string,\n children: PropTypes.node.isRequired,\n};\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React, { useState } from 'react';
|
|
3
|
+
import { Container, Row, Col, Hyperlink, } from '@openedx/paragon';
|
|
4
|
+
import { useSiteEvent } from './hooks';
|
|
5
|
+
import { FormattedMessage, IntlProvider, getMessages, getLocale, LOCALE_CHANGED, } from '../i18n';
|
|
6
|
+
function NotFoundPage() {
|
|
7
|
+
const [locale, setLocale] = useState(getLocale());
|
|
8
|
+
useSiteEvent(LOCALE_CHANGED, () => {
|
|
9
|
+
setLocale(getLocale());
|
|
10
|
+
});
|
|
11
|
+
return (_jsx(IntlProvider, { locale: locale, messages: getMessages(), children: _jsx(Container, { fluid: true, className: "py-5 justify-content-center align-items-start text-center", children: _jsx(Row, { children: _jsxs(Col, { children: [_jsx("p", { className: "h2 mb-3", children: _jsx(FormattedMessage, { id: "not.found.page.heading", defaultMessage: "404", description: "heading for page not found" }) }), _jsx("p", { className: "text-muted", children: _jsx(FormattedMessage, { id: "not.found.page.message", defaultMessage: "The page you're looking for could not be found.", description: "message displayed when a page is not found" }) }), _jsx(Hyperlink, { destination: "/", children: _jsx(FormattedMessage, { id: "not.found.page.link.text", defaultMessage: "Go to the homepage", description: "link text to navigate to the homepage from a 404 page" }) })] }) }) }) }));
|
|
12
|
+
}
|
|
13
|
+
export default NotFoundPage;
|
|
14
|
+
//# sourceMappingURL=NotFoundPage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NotFoundPage.js","sourceRoot":"","sources":["../../../runtime/react/NotFoundPage.jsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACxC,OAAO,EACL,SAAS,EAAE,GAAG,EAAE,GAAG,EAAE,SAAS,GAC/B,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,SAAS,EACT,cAAc,GACf,MAAM,SAAS,CAAC;AAGjB,SAAS,YAAY;IACnB,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC;IAElD,YAAY,CAAC,cAAc,EAAE,GAAG,EAAE;QAChC,SAAS,CAAC,SAAS,EAAE,CAAC,CAAC;IACzB,CAAC,CAAC,CAAC;IAEH,OAAO,CACL,KAAC,YAAY,IAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,YACnD,KAAC,SAAS,IAAC,KAAK,QAAC,SAAS,EAAC,2DAA2D,YACpF,KAAC,GAAG,cACF,MAAC,GAAG,eACF,YAAG,SAAS,EAAC,SAAS,YACpB,KAAC,gBAAgB,IACf,EAAE,EAAC,wBAAwB,EAC3B,cAAc,EAAC,KAAK,EACpB,WAAW,EAAC,4BAA4B,GACxC,GACA,EACJ,YAAG,SAAS,EAAC,YAAY,YACvB,KAAC,gBAAgB,IACf,EAAE,EAAC,wBAAwB,EAC3B,cAAc,EAAC,iDAAiD,EAChE,WAAW,EAAC,4CAA4C,GACxD,GACA,EACJ,KAAC,SAAS,IAAC,WAAW,EAAC,GAAG,YACxB,KAAC,gBAAgB,IACf,EAAE,EAAC,0BAA0B,EAC7B,cAAc,EAAC,oBAAoB,EACnC,WAAW,EAAC,uDAAuD,GACnE,GACQ,IACR,GACF,GACI,GACC,CAChB,CAAC;AACJ,CAAC;AAED,eAAe,YAAY,CAAC","sourcesContent":["import React, { useState } from 'react';\nimport {\n Container, Row, Col, Hyperlink,\n} from '@openedx/paragon';\n\nimport { useSiteEvent } from './hooks';\nimport {\n FormattedMessage,\n IntlProvider,\n getMessages,\n getLocale,\n LOCALE_CHANGED,\n} from '../i18n';\n\n\nfunction NotFoundPage() {\n const [locale, setLocale] = useState(getLocale());\n\n useSiteEvent(LOCALE_CHANGED, () => {\n setLocale(getLocale());\n });\n\n return (\n <IntlProvider locale={locale} messages={getMessages()}>\n <Container fluid className=\"py-5 justify-content-center align-items-start text-center\">\n <Row>\n <Col>\n <p className=\"h2 mb-3\">\n <FormattedMessage\n id=\"not.found.page.heading\"\n defaultMessage=\"404\"\n description=\"heading for page not found\"\n />\n </p>\n <p className=\"text-muted\">\n <FormattedMessage\n id=\"not.found.page.message\"\n defaultMessage=\"The page you're looking for could not be found.\"\n description=\"message displayed when a page is not found\"\n />\n </p>\n <Hyperlink destination=\"/\">\n <FormattedMessage\n id=\"not.found.page.link.text\"\n defaultMessage=\"Go to the homepage\"\n description=\"link text to navigate to the homepage from a 404 page\"\n />\n </Hyperlink>\n </Col>\n </Row>\n </Container>\n </IntlProvider>\n );\n}\n\nexport default NotFoundPage;\n"]}
|
|
@@ -13,6 +13,7 @@ export { default as AuthenticatedPageRoute } from './AuthenticatedPageRoute';
|
|
|
13
13
|
export { default as Divider } from './Divider';
|
|
14
14
|
export { default as ErrorBoundary } from './ErrorBoundary';
|
|
15
15
|
export { default as ErrorPage } from './ErrorPage';
|
|
16
|
+
export { default as NotFoundPage } from './NotFoundPage';
|
|
16
17
|
export { useSiteEvent, useAuthenticatedUser, useSiteConfig, useAppConfig } from './hooks';
|
|
17
18
|
export { default as LoginRedirect } from './LoginRedirect';
|
|
18
19
|
export { default as PageWrap } from './PageWrap';
|
|
@@ -13,6 +13,7 @@ export { default as AuthenticatedPageRoute } from './AuthenticatedPageRoute';
|
|
|
13
13
|
export { default as Divider } from './Divider';
|
|
14
14
|
export { default as ErrorBoundary } from './ErrorBoundary';
|
|
15
15
|
export { default as ErrorPage } from './ErrorPage';
|
|
16
|
+
export { default as NotFoundPage } from './NotFoundPage';
|
|
16
17
|
export { useSiteEvent, useAuthenticatedUser, useSiteConfig, useAppConfig } from './hooks';
|
|
17
18
|
export { default as LoginRedirect } from './LoginRedirect';
|
|
18
19
|
export { default as PageWrap } from './PageWrap';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../runtime/react/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,OAAO,IAAI,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC1F,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,YAAY,CAAC","sourcesContent":["/**\n * #### Import members from **@openedx/frontend-base** React\n * The React module provides a variety of React components, hooks, and contexts for use in an\n * application.\n *\n * @module React\n */\n\nexport { default as CurrentAppContext } from './CurrentAppContext';\nexport { default as CurrentAppProvider } from './CurrentAppProvider';\nexport { default as SiteContext } from './SiteContext';\nexport { default as SiteProvider } from './SiteProvider';\nexport { default as AuthenticatedPageRoute } from './AuthenticatedPageRoute';\nexport { default as Divider } from './Divider';\nexport { default as ErrorBoundary } from './ErrorBoundary';\nexport { default as ErrorPage } from './ErrorPage';\nexport { useSiteEvent, useAuthenticatedUser, useSiteConfig, useAppConfig } from './hooks';\nexport { default as LoginRedirect } from './LoginRedirect';\nexport { default as PageWrap } from './PageWrap';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../runtime/react/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,OAAO,IAAI,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC1F,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,YAAY,CAAC","sourcesContent":["/**\n * #### Import members from **@openedx/frontend-base** React\n * The React module provides a variety of React components, hooks, and contexts for use in an\n * application.\n *\n * @module React\n */\n\nexport { default as CurrentAppContext } from './CurrentAppContext';\nexport { default as CurrentAppProvider } from './CurrentAppProvider';\nexport { default as SiteContext } from './SiteContext';\nexport { default as SiteProvider } from './SiteProvider';\nexport { default as AuthenticatedPageRoute } from './AuthenticatedPageRoute';\nexport { default as Divider } from './Divider';\nexport { default as ErrorBoundary } from './ErrorBoundary';\nexport { default as ErrorPage } from './ErrorPage';\nexport { default as NotFoundPage } from './NotFoundPage';\nexport { useSiteEvent, useAuthenticatedUser, useSiteConfig, useAppConfig } from './hooks';\nexport { default as LoginRedirect } from './LoginRedirect';\nexport { default as PageWrap } from './PageWrap';\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { redirect } from 'react-router';
|
|
2
|
+
import { getAuthenticatedUser, getLoginRedirectUrl } from '../auth';
|
|
3
|
+
import { getUrlByRouteRole } from './utils';
|
|
4
|
+
const loginRole = 'org.openedx.frontend.role.login';
|
|
5
|
+
export default function authenticatedLoader({ request }) {
|
|
6
|
+
const authenticatedUser = getAuthenticatedUser();
|
|
7
|
+
if (authenticatedUser !== null) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
const requestUrl = new URL(request.url);
|
|
11
|
+
const loginUrl = getUrlByRouteRole(loginRole);
|
|
12
|
+
// Internal login route → SPA redirect with a relative ?next so the login
|
|
13
|
+
// page can navigate() back without a full page refresh.
|
|
14
|
+
if (loginUrl === null || loginUrl === void 0 ? void 0 : loginUrl.startsWith('/')) {
|
|
15
|
+
return redirect(`${loginUrl}?next=${encodeURIComponent(requestUrl.pathname)}`);
|
|
16
|
+
}
|
|
17
|
+
// No login role found (or it's defined as an external route, which is not
|
|
18
|
+
// supported). Use loginUrl from siteConfig and the full href for the return
|
|
19
|
+
// path so the login service redirects back to the correct origin after
|
|
20
|
+
// login.
|
|
21
|
+
const fullLoginUrl = getLoginRedirectUrl(requestUrl.href);
|
|
22
|
+
// Return a never-resolving promise so React Router keeps waiting (and does
|
|
23
|
+
// not attempt to render the route) while the browser navigates away.
|
|
24
|
+
global.location.assign(fullLoginUrl);
|
|
25
|
+
return new Promise(() => { });
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=authenticatedLoader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authenticatedLoader.js","sourceRoot":"","sources":["../../../runtime/routing/authenticatedLoader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE5C,MAAM,SAAS,GAAG,iCAAiC,CAAC;AAEpD,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,EAAE,OAAO,EAAsB;IACzE,MAAM,iBAAiB,GAAG,oBAAoB,EAAE,CAAC;IACjD,IAAI,iBAAiB,KAAK,IAAI,EAAE,CAAC;QAC/B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACxC,MAAM,QAAQ,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC;IAE9C,yEAAyE;IACzE,wDAAwD;IACxD,IAAI,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC9B,OAAO,QAAQ,CAAC,GAAG,QAAQ,SAAS,kBAAkB,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACjF,CAAC;IAED,0EAA0E;IAC1E,4EAA4E;IAC5E,uEAAuE;IACvE,SAAS;IACT,MAAM,YAAY,GAAG,mBAAmB,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAE1D,2EAA2E;IAC3E,qEAAqE;IACrE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IACrC,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAChC,CAAC","sourcesContent":["import { LoaderFunctionArgs, redirect } from 'react-router';\nimport { getAuthenticatedUser, getLoginRedirectUrl } from '../auth';\nimport { getUrlByRouteRole } from './utils';\n\nconst loginRole = 'org.openedx.frontend.role.login';\n\nexport default function authenticatedLoader({ request }: LoaderFunctionArgs) {\n const authenticatedUser = getAuthenticatedUser();\n if (authenticatedUser !== null) {\n return null;\n }\n\n const requestUrl = new URL(request.url);\n const loginUrl = getUrlByRouteRole(loginRole);\n\n // Internal login route → SPA redirect with a relative ?next so the login\n // page can navigate() back without a full page refresh.\n if (loginUrl?.startsWith('/')) {\n return redirect(`${loginUrl}?next=${encodeURIComponent(requestUrl.pathname)}`);\n }\n\n // No login role found (or it's defined as an external route, which is not\n // supported). Use loginUrl from siteConfig and the full href for the return\n // path so the login service redirects back to the correct origin after\n // login.\n const fullLoginUrl = getLoginRedirectUrl(requestUrl.href);\n\n // Return a never-resolving promise so React Router keeps waiting (and does\n // not attempt to render the route) while the browser navigates away.\n global.location.assign(fullLoginUrl);\n return new Promise(() => { });\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../runtime/routing/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC","sourcesContent":["export * from './utils';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../runtime/routing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACvE,cAAc,SAAS,CAAC","sourcesContent":["export { default as authenticatedLoader } from './authenticatedLoader';\nexport * from './utils';\n"]}
|
|
@@ -1,14 +1,29 @@
|
|
|
1
1
|
import { getSiteConfig } from '../config';
|
|
2
|
-
|
|
2
|
+
function findRoleInRoutes(routes, role, prefix = '') {
|
|
3
3
|
var _a, _b;
|
|
4
|
+
for (const route of routes) {
|
|
5
|
+
const segment = (_a = route.path) !== null && _a !== void 0 ? _a : '';
|
|
6
|
+
const fullPath = segment.startsWith('/') ? segment : `${prefix}/${segment}`.replace(/\/+/g, '/');
|
|
7
|
+
if (((_b = route.handle) === null || _b === void 0 ? void 0 : _b.role) === role) {
|
|
8
|
+
return fullPath || null;
|
|
9
|
+
}
|
|
10
|
+
if (Array.isArray(route.children)) {
|
|
11
|
+
const found = findRoleInRoutes(route.children, role, fullPath);
|
|
12
|
+
if (found !== null) {
|
|
13
|
+
return found;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
export function getUrlByRouteRole(role) {
|
|
4
20
|
const { apps, externalRoutes } = getSiteConfig();
|
|
5
21
|
if (apps) {
|
|
6
22
|
for (const app of apps) {
|
|
7
23
|
if (Array.isArray(app.routes)) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
24
|
+
const found = findRoleInRoutes(app.routes, role);
|
|
25
|
+
if (found !== null) {
|
|
26
|
+
return found;
|
|
12
27
|
}
|
|
13
28
|
}
|
|
14
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../runtime/routing/utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../runtime/routing/utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C,SAAS,gBAAgB,CAAC,MAAqB,EAAE,IAAY,EAAE,MAAM,GAAG,EAAE;;IACxE,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,OAAO,GAAG,MAAA,KAAK,CAAC,IAAI,mCAAI,EAAE,CAAC;QACjC,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,OAAO,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAEjG,IAAI,CAAA,MAAA,KAAK,CAAC,MAAM,0CAAE,IAAI,MAAK,IAAI,EAAE,CAAC;YAChC,OAAO,QAAQ,IAAI,IAAI,CAAC;QAC1B,CAAC;QAED,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;YAClC,MAAM,KAAK,GAAG,gBAAgB,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;YAC/D,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;gBACnB,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,GAAG,aAAa,EAAE,CAAC;IAEjD,IAAI,IAAI,EAAE,CAAC;QACT,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC9B,MAAM,KAAK,GAAG,gBAAgB,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;gBACjD,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;oBACnB,OAAO,KAAK,CAAC;gBACf,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI,cAAc,EAAE,CAAC;QACnB,KAAK,MAAM,aAAa,IAAI,cAAc,EAAE,CAAC;YAC3C,IAAI,aAAa,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;gBAChC,OAAO,aAAa,CAAC,GAAG,CAAC;YAC3B,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAAkB;IAClD,OAAO,KAAK,CAAC,MAAM,KAAK,SAAS,IAAI,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC;AAC9D,CAAC","sourcesContent":["import { RouteObject } from 'react-router';\n\nimport { RoleRouteObject } from '../../types';\nimport { getSiteConfig } from '../config';\n\nfunction findRoleInRoutes(routes: RouteObject[], role: string, prefix = ''): string | null {\n for (const route of routes) {\n const segment = route.path ?? '';\n const fullPath = segment.startsWith('/') ? segment : `${prefix}/${segment}`.replace(/\\/+/g, '/');\n\n if (route.handle?.role === role) {\n return fullPath || null;\n }\n\n if (Array.isArray(route.children)) {\n const found = findRoleInRoutes(route.children, role, fullPath);\n if (found !== null) {\n return found;\n }\n }\n }\n return null;\n}\n\nexport function getUrlByRouteRole(role: string) {\n const { apps, externalRoutes } = getSiteConfig();\n\n if (apps) {\n for (const app of apps) {\n if (Array.isArray(app.routes)) {\n const found = findRoleInRoutes(app.routes, role);\n if (found !== null) {\n return found;\n }\n }\n }\n }\n\n if (externalRoutes) {\n for (const externalRoute of externalRoutes) {\n if (externalRoute.role === role) {\n return externalRoute.url;\n }\n }\n }\n\n return null;\n}\n\nexport function isRoleRouteObject(match: RouteObject): match is RoleRouteObject {\n return match.handle !== undefined && 'role' in match.handle;\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { WidgetOperation } from './types';
|
|
2
|
-
export declare function useWidgets():
|
|
3
|
-
export declare function useWidgetsForId(id: string, componentProps?: Record<string, unknown>):
|
|
1
|
+
import { WidgetList, WidgetOperation } from './types';
|
|
2
|
+
export declare function useWidgets(): WidgetList;
|
|
3
|
+
export declare function useWidgetsForId(id: string, componentProps?: Record<string, unknown>): WidgetList;
|
|
4
4
|
export declare function useWidgetOperations(id: string): WidgetOperation[];
|
|
5
5
|
export declare function useSortedWidgetOperations(id: string): WidgetOperation[];
|
|
6
6
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../../../runtime/slots/widget/hooks.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7D,OAAO,EAAE,iCAAiC,EAAE,MAAM,UAAU,CAAC;AAE7D,O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AAM,UAAU,qBAAqB,CAAC,MAAc,EAAE,QAAgB;IACpE,MAAM,UAAU,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAE/C,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAA0B,EAAE,CAAC,CAAC;IACpE,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,WAAW,GAAG,GAAG,EAAE;YACvB,IAAI,WAAW,GAA4B,EAAE,CAAC;YAC9C,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;gBACnC,IAAI,iCAAiC,CAAC,SAAS,CAAC,EAAE,CAAC;oBACjD,IAAI,wBAAwB,CAAC,SAAS,CAAC,EAAE,CAAC;wBACxC,IAAI,SAAS,CAAC,SAAS,KAAK,QAAQ,EAAE,CAAC;4BACrC,WAAW,mCAAQ,WAAW,GAAK,SAAS,CAAC,OAAO,CAAE,CAAC;wBACzD,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;YACD,OAAO,WAAW,CAAC;QACrB,CAAC,CAAC;QAEF,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC;IAC5B,CAAC,EAAE,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC;IAE3B,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { useContext, useEffect, useState } from 'react';\nimport { useSlotContext, useSlotOperations } from '../hooks';\nimport { isSlotOperationConditionSatisfied } from '../utils';\nimport { WidgetOperation } from './types';\nimport { createWidgets, isWidgetAbsoluteOperation, isWidgetOperation, isWidgetOptionsOperation, isWidgetRelativeOperation } from './utils';\nimport WidgetContext from './WidgetContext';\n\nexport function useWidgets() {\n const { id, ...props } = useSlotContext();\n delete props.children;\n return useWidgetsForId(id, props);\n}\n\nexport function useWidgetsForId(id: string, componentProps?: Record<string, unknown>) {\n const operations = useSortedWidgetOperations(id);\n return createWidgets(operations, componentProps);\n}\n\nexport function useWidgetOperations(id: string) {\n const operations = useSlotOperations(id);\n const [widgetOperations, setWidgetOperations] = useState<WidgetOperation[]>([]);\n\n useEffect(() => {\n const filteredOperations = operations.filter((operation): operation is WidgetOperation => {\n return isWidgetOperation(operation) && isSlotOperationConditionSatisfied(operation);\n });\n\n setWidgetOperations(filteredOperations);\n }, [operations]);\n\n return widgetOperations;\n}\n\nexport function useSortedWidgetOperations(id: string) {\n const operations = useWidgetOperations(id);\n const [sortedOperations, setSortedOperations] = useState<WidgetOperation[]>([]);\n\n useEffect(() => {\n // This sorts widget operations in an order that guarantees that any 'related' widgets\n // needed by relatively positioned operations (INSERT_AFTER, INSERT_BEFORE) should already exist\n // by the time the relative operations are evaluated. It means the declaration order of\n // operations in SiteConfig does not prevent an operation from interacting with a widget that was\n // declared 'later'.\n const sortedOperations = operations.sort((a: WidgetOperation, b: WidgetOperation) => {\n // If both operations are widget operations, there are special sorting rules.\n const aAbsolute = isWidgetAbsoluteOperation(a);\n const bAbsolute = isWidgetAbsoluteOperation(b);\n if (aAbsolute && bAbsolute) {\n return 0;\n } else if (aAbsolute) {\n return -1;\n } else if (bAbsolute) {\n return 1;\n } else if (isWidgetRelativeOperation(a) && isWidgetRelativeOperation(b)) {\n if (a.id === b.relatedId) {\n return -1;\n } else if (b.id === a.relatedId) {\n return 1;\n }\n }\n\n return 0;\n });\n\n setSortedOperations(sortedOperations);\n }, [operations]);\n\n return sortedOperations;\n}\n\n/**\n * useWidgetOptions iterates through the slot's operations to find any that are \"widget options\"\n * operations specific to this widget. It merges these into a single object and returns them -\n * operations are merged in declaration order, meaning last one in wins. useWidgetOptions only\n * triggers a re-render when the options change.\n */\nexport function useWidgetOptions() {\n const { slotId, widgetId } = useContext(WidgetContext);\n return useWidgetOptionsForId(slotId, widgetId);\n}\n\nexport function useWidgetOptionsForId(slotId: string, widgetId: string) {\n const operations = useWidgetOperations(slotId);\n\n const [options, setOptions] = useState<Record<string, unknown>>({});\n useEffect(() => {\n const findOptions = () => {\n let nextOptions: Record<string, unknown> = {};\n for (const operation of operations) {\n if (isSlotOperationConditionSatisfied(operation)) {\n if (isWidgetOptionsOperation(operation)) {\n if (operation.relatedId === widgetId) {\n nextOptions = { ...nextOptions, ...operation.options };\n }\n }\n }\n }\n return nextOptions;\n };\n\n setOptions(findOptions());\n }, [widgetId, operations]);\n\n return options;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../../../runtime/slots/widget/hooks.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7D,OAAO,EAAE,iCAAiC,EAAE,MAAM,UAAU,CAAC;AAE7D,OAAO,EAAE,aAAa,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAC3I,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAE5C,MAAM,UAAU,UAAU;IACxB,MAAM,KAAmB,cAAc,EAAE,EAAnC,EAAE,EAAE,OAA+B,EAA1B,KAAK,cAAd,MAAgB,CAAmB,CAAC;IAC1C,OAAO,KAAK,CAAC,QAAQ,CAAC;IACtB,OAAO,eAAe,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,EAAU,EAAE,cAAwC;IAClF,MAAM,UAAU,GAAG,yBAAyB,CAAC,EAAE,CAAC,CAAC;IACjD,OAAO,aAAa,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,EAAU;IAC5C,MAAM,UAAU,GAAG,iBAAiB,CAAC,EAAE,CAAC,CAAC;IACzC,MAAM,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,GAAG,QAAQ,CAAoB,EAAE,CAAC,CAAC;IAEhF,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,kBA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O,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { useContext, useEffect, useState } from 'react';\nimport { useSlotContext, useSlotOperations } from '../hooks';\nimport { isSlotOperationConditionSatisfied } from '../utils';\nimport { WidgetList, WidgetOperation } from './types';\nimport { createWidgets, isWidgetAbsoluteOperation, isWidgetOperation, isWidgetOptionsOperation, isWidgetRelativeOperation } from './utils';\nimport WidgetContext from './WidgetContext';\n\nexport function useWidgets(): WidgetList {\n const { id, ...props } = useSlotContext();\n delete props.children;\n return useWidgetsForId(id, props);\n}\n\nexport function useWidgetsForId(id: string, componentProps?: Record<string, unknown>): WidgetList {\n const operations = useSortedWidgetOperations(id);\n return createWidgets(operations, componentProps);\n}\n\nexport function useWidgetOperations(id: string) {\n const operations = useSlotOperations(id);\n const [widgetOperations, setWidgetOperations] = useState<WidgetOperation[]>([]);\n\n useEffect(() => {\n const filteredOperations = operations.filter((operation): operation is WidgetOperation => {\n return isWidgetOperation(operation) && isSlotOperationConditionSatisfied(operation);\n });\n\n setWidgetOperations(filteredOperations);\n }, [operations]);\n\n return widgetOperations;\n}\n\nexport function useSortedWidgetOperations(id: string) {\n const operations = useWidgetOperations(id);\n const [sortedOperations, setSortedOperations] = useState<WidgetOperation[]>([]);\n\n useEffect(() => {\n // This sorts widget operations in an order that guarantees that any 'related' widgets\n // needed by relatively positioned operations (INSERT_AFTER, INSERT_BEFORE) should already exist\n // by the time the relative operations are evaluated. It means the declaration order of\n // operations in SiteConfig does not prevent an operation from interacting with a widget that was\n // declared 'later'.\n const sortedOperations = operations.sort((a: WidgetOperation, b: WidgetOperation) => {\n // If both operations are widget operations, there are special sorting rules.\n const aAbsolute = isWidgetAbsoluteOperation(a);\n const bAbsolute = isWidgetAbsoluteOperation(b);\n if (aAbsolute && bAbsolute) {\n return 0;\n } else if (aAbsolute) {\n return -1;\n } else if (bAbsolute) {\n return 1;\n } else if (isWidgetRelativeOperation(a) && isWidgetRelativeOperation(b)) {\n if (a.id === b.relatedId) {\n return -1;\n } else if (b.id === a.relatedId) {\n return 1;\n }\n }\n\n return 0;\n });\n\n setSortedOperations(sortedOperations);\n }, [operations]);\n\n return sortedOperations;\n}\n\n/**\n * useWidgetOptions iterates through the slot's operations to find any that are \"widget options\"\n * operations specific to this widget. It merges these into a single object and returns them -\n * operations are merged in declaration order, meaning last one in wins. useWidgetOptions only\n * triggers a re-render when the options change.\n */\nexport function useWidgetOptions() {\n const { slotId, widgetId } = useContext(WidgetContext);\n return useWidgetOptionsForId(slotId, widgetId);\n}\n\nexport function useWidgetOptionsForId(slotId: string, widgetId: string) {\n const operations = useWidgetOperations(slotId);\n\n const [options, setOptions] = useState<Record<string, unknown>>({});\n useEffect(() => {\n const findOptions = () => {\n let nextOptions: Record<string, unknown> = {};\n for (const operation of operations) {\n if (isSlotOperationConditionSatisfied(operation)) {\n if (isWidgetOptionsOperation(operation)) {\n if (operation.relatedId === widgetId) {\n nextOptions = { ...nextOptions, ...operation.options };\n }\n }\n }\n }\n return nextOptions;\n };\n\n setOptions(findOptions());\n }, [widgetId, operations]);\n\n return options;\n}\n"]}
|
|
@@ -96,5 +96,13 @@ export type WidgetOperation = WidgetAbsoluteOperation | WidgetRelativeOperation;
|
|
|
96
96
|
*/
|
|
97
97
|
export interface IdentifiedWidget {
|
|
98
98
|
id: string;
|
|
99
|
+
role?: string;
|
|
99
100
|
node: ReactNode;
|
|
100
101
|
}
|
|
102
|
+
export interface WidgetList extends Array<ReactNode> {
|
|
103
|
+
identified: IdentifiedWidget[];
|
|
104
|
+
byId(id: string): ReactNode[];
|
|
105
|
+
withoutId(id: string): ReactNode[];
|
|
106
|
+
byRole(role: string): ReactNode[];
|
|
107
|
+
withoutRole(role: string): ReactNode[];
|
|
108
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../runtime/slots/widget/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,MAAM,CAAN,IAAY,oBAmCX;AAnCD,WAAY,oBAAoB;IAC9B;;OAEG;IACH,+CAAuB,CAAA;IAEvB;;OAEG;IACH,iDAAyB,CAAA;IAEzB;;OAEG;IACH,0DAAkC,CAAA;IAElC;;OAEG;IACH,4DAAoC,CAAA;IAEpC;;OAEG;IACH,iDAAyB,CAAA;IAEzB;;OAEG;IACH,+CAAuB,CAAA;IAEvB;;OAEG;IACH,iDAAyB,CAAA;AAC3B,CAAC,EAnCW,oBAAoB,KAApB,oBAAoB,QAmC/B","sourcesContent":["/**\n * Base UI Widget Operations\n *\n * \"Widget\" operations are a sub-type of UI operations which allow manipulation of the list of widgets (UI components) loaded into the slot. Widget operations are divided further into two sub-types: absolute and relative.\n *\n * Absolute widget operations allow simple list operations like appending and prepending which don't depend on any other list elements.\n *\n * Relative widget operations depend on a relationship to some other list element, such as \"insert before\" and \"insert after\". Some affect those elements, some add something to the list near them.\n */\n\nimport { ReactNode } from 'react';\nimport { BaseSlotOperation } from '../types';\n\nexport enum WidgetOperationTypes {\n /**\n * Adds a widget to the end of the slot's list of widgets.\n */\n APPEND = 'widgetAppend',\n\n /**\n * Adds a widget to the beginning of the slot's list of widgets.\n */\n PREPEND = 'widgetPrepend',\n\n /**\n * Adds a widget after the specified widget ID. Multiple \"insert after\" operations on the same widget ID occur in the order they were declared.\n */\n INSERT_AFTER = 'widgetInsertAfter',\n\n /**\n * Adds a widget before the specified widget ID. Multiple \"insert after\" operations on the same widget ID occur in the order they were declared.\n */\n INSERT_BEFORE = 'widgetInsertBefore',\n\n /**\n * Removes the specified widget ID and adds a widget in its place. Multiple \"replace\" operations on the same widget ID occur in the order they were declared, and only the first will succeed unless the new widget's ID is the same as the one that was removed.\n */\n REPLACE = 'widgetReplace',\n\n /**\n * Removes the specified widget ID from the slot's list of widgets. Subsequent relative widget operations on that widget ID will not be applied.\n */\n REMOVE = 'widgetRemove',\n\n /**\n * Provides options to the specified widget ID. Multiple \"options\" operations on the same widget ID will merge with and override any duplicate properties in the options object - last one in wins.\n */\n OPTIONS = 'widgetOptions',\n}\n\nexport type AbsoluteWidgetOperationTypes = WidgetOperationTypes.APPEND | WidgetOperationTypes.PREPEND;\n\nexport type RelativeWidgetOperationTypes = WidgetOperationTypes.INSERT_AFTER | WidgetOperationTypes.INSERT_BEFORE | WidgetOperationTypes.REPLACE | WidgetOperationTypes.OPTIONS;\n\nexport interface BaseWidgetOperation extends BaseSlotOperation {\n op: WidgetOperationTypes,\n}\n\n// Widget renderer props\n\nexport interface WidgetComponentProps {\n component: React.ComponentType,\n}\n\nexport interface WidgetElementProps {\n element: ReactNode,\n}\n\nexport interface WidgetIFrameProps {\n url: string,\n title: string,\n}\n\nexport type WidgetRendererProps = (\n WidgetComponentProps | WidgetElementProps | WidgetIFrameProps\n);\n\nexport interface WidgetIdentityProps {\n id: string,\n role?: string,\n}\n\nexport interface WidgetRelationshipProps {\n relatedId: string,\n}\n\n// Concrete UI Widget Operations\n\nexport type WidgetAppendOperation = BaseWidgetOperation & WidgetIdentityProps & WidgetRendererProps & {\n op: WidgetOperationTypes.APPEND,\n};\n\nexport type WidgetPrependOperation = BaseWidgetOperation & WidgetIdentityProps & WidgetRendererProps & {\n op: WidgetOperationTypes.PREPEND,\n};\n\nexport type WidgetInsertAfterOperation = BaseWidgetOperation & WidgetIdentityProps & WidgetRendererProps & WidgetRelationshipProps & {\n op: WidgetOperationTypes.INSERT_AFTER,\n};\n\nexport type WidgetInsertBeforeOperation = BaseWidgetOperation & WidgetIdentityProps & WidgetRendererProps & WidgetRelationshipProps & {\n op: WidgetOperationTypes.INSERT_BEFORE,\n};\n\nexport type WidgetRemoveOperation = BaseWidgetOperation & WidgetRelationshipProps & {\n op: WidgetOperationTypes.REMOVE,\n};\n\nexport type WidgetOptionsOperation = BaseWidgetOperation & WidgetRelationshipProps & {\n op: WidgetOperationTypes.OPTIONS,\n options: Record<string, unknown>,\n};\n\nexport type WidgetReplaceOperation = BaseWidgetOperation & WidgetIdentityProps & WidgetRendererProps & WidgetRelationshipProps & { op: WidgetOperationTypes.REPLACE };\n\nexport type WidgetAbsoluteOperation = WidgetAppendOperation | WidgetPrependOperation;\n\nexport type WidgetRelativeRendererOperation = WidgetInsertAfterOperation | WidgetInsertBeforeOperation | WidgetReplaceOperation;\n\nexport type WidgetRelativeOperation = WidgetRelativeRendererOperation | WidgetRemoveOperation | WidgetOptionsOperation;\n\nexport type WidgetRendererOperation = WidgetAbsoluteOperation | WidgetRelativeRendererOperation;\n\nexport type WidgetOperation = WidgetAbsoluteOperation | WidgetRelativeOperation;\n\n/**\n * An identified widget is a simple data structure to associate an ID with a ReactNode so we can\n * apply widget operations to our list of widgets. It helps us find a ReactNode with a particular\n * ID for relative widget operations.\n */\nexport interface IdentifiedWidget {\n id: string,\n node: ReactNode,\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../runtime/slots/widget/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,MAAM,CAAN,IAAY,oBAmCX;AAnCD,WAAY,oBAAoB;IAC9B;;OAEG;IACH,+CAAuB,CAAA;IAEvB;;OAEG;IACH,iDAAyB,CAAA;IAEzB;;OAEG;IACH,0DAAkC,CAAA;IAElC;;OAEG;IACH,4DAAoC,CAAA;IAEpC;;OAEG;IACH,iDAAyB,CAAA;IAEzB;;OAEG;IACH,+CAAuB,CAAA;IAEvB;;OAEG;IACH,iDAAyB,CAAA;AAC3B,CAAC,EAnCW,oBAAoB,KAApB,oBAAoB,QAmC/B","sourcesContent":["/**\n * Base UI Widget Operations\n *\n * \"Widget\" operations are a sub-type of UI operations which allow manipulation of the list of widgets (UI components) loaded into the slot. Widget operations are divided further into two sub-types: absolute and relative.\n *\n * Absolute widget operations allow simple list operations like appending and prepending which don't depend on any other list elements.\n *\n * Relative widget operations depend on a relationship to some other list element, such as \"insert before\" and \"insert after\". Some affect those elements, some add something to the list near them.\n */\n\nimport { ReactNode } from 'react';\nimport { BaseSlotOperation } from '../types';\n\nexport enum WidgetOperationTypes {\n /**\n * Adds a widget to the end of the slot's list of widgets.\n */\n APPEND = 'widgetAppend',\n\n /**\n * Adds a widget to the beginning of the slot's list of widgets.\n */\n PREPEND = 'widgetPrepend',\n\n /**\n * Adds a widget after the specified widget ID. Multiple \"insert after\" operations on the same widget ID occur in the order they were declared.\n */\n INSERT_AFTER = 'widgetInsertAfter',\n\n /**\n * Adds a widget before the specified widget ID. Multiple \"insert after\" operations on the same widget ID occur in the order they were declared.\n */\n INSERT_BEFORE = 'widgetInsertBefore',\n\n /**\n * Removes the specified widget ID and adds a widget in its place. Multiple \"replace\" operations on the same widget ID occur in the order they were declared, and only the first will succeed unless the new widget's ID is the same as the one that was removed.\n */\n REPLACE = 'widgetReplace',\n\n /**\n * Removes the specified widget ID from the slot's list of widgets. Subsequent relative widget operations on that widget ID will not be applied.\n */\n REMOVE = 'widgetRemove',\n\n /**\n * Provides options to the specified widget ID. Multiple \"options\" operations on the same widget ID will merge with and override any duplicate properties in the options object - last one in wins.\n */\n OPTIONS = 'widgetOptions',\n}\n\nexport type AbsoluteWidgetOperationTypes = WidgetOperationTypes.APPEND | WidgetOperationTypes.PREPEND;\n\nexport type RelativeWidgetOperationTypes = WidgetOperationTypes.INSERT_AFTER | WidgetOperationTypes.INSERT_BEFORE | WidgetOperationTypes.REPLACE | WidgetOperationTypes.OPTIONS;\n\nexport interface BaseWidgetOperation extends BaseSlotOperation {\n op: WidgetOperationTypes,\n}\n\n// Widget renderer props\n\nexport interface WidgetComponentProps {\n component: React.ComponentType,\n}\n\nexport interface WidgetElementProps {\n element: ReactNode,\n}\n\nexport interface WidgetIFrameProps {\n url: string,\n title: string,\n}\n\nexport type WidgetRendererProps = (\n WidgetComponentProps | WidgetElementProps | WidgetIFrameProps\n);\n\nexport interface WidgetIdentityProps {\n id: string,\n role?: string,\n}\n\nexport interface WidgetRelationshipProps {\n relatedId: string,\n}\n\n// Concrete UI Widget Operations\n\nexport type WidgetAppendOperation = BaseWidgetOperation & WidgetIdentityProps & WidgetRendererProps & {\n op: WidgetOperationTypes.APPEND,\n};\n\nexport type WidgetPrependOperation = BaseWidgetOperation & WidgetIdentityProps & WidgetRendererProps & {\n op: WidgetOperationTypes.PREPEND,\n};\n\nexport type WidgetInsertAfterOperation = BaseWidgetOperation & WidgetIdentityProps & WidgetRendererProps & WidgetRelationshipProps & {\n op: WidgetOperationTypes.INSERT_AFTER,\n};\n\nexport type WidgetInsertBeforeOperation = BaseWidgetOperation & WidgetIdentityProps & WidgetRendererProps & WidgetRelationshipProps & {\n op: WidgetOperationTypes.INSERT_BEFORE,\n};\n\nexport type WidgetRemoveOperation = BaseWidgetOperation & WidgetRelationshipProps & {\n op: WidgetOperationTypes.REMOVE,\n};\n\nexport type WidgetOptionsOperation = BaseWidgetOperation & WidgetRelationshipProps & {\n op: WidgetOperationTypes.OPTIONS,\n options: Record<string, unknown>,\n};\n\nexport type WidgetReplaceOperation = BaseWidgetOperation & WidgetIdentityProps & WidgetRendererProps & WidgetRelationshipProps & { op: WidgetOperationTypes.REPLACE };\n\nexport type WidgetAbsoluteOperation = WidgetAppendOperation | WidgetPrependOperation;\n\nexport type WidgetRelativeRendererOperation = WidgetInsertAfterOperation | WidgetInsertBeforeOperation | WidgetReplaceOperation;\n\nexport type WidgetRelativeOperation = WidgetRelativeRendererOperation | WidgetRemoveOperation | WidgetOptionsOperation;\n\nexport type WidgetRendererOperation = WidgetAbsoluteOperation | WidgetRelativeRendererOperation;\n\nexport type WidgetOperation = WidgetAbsoluteOperation | WidgetRelativeOperation;\n\n/**\n * An identified widget is a simple data structure to associate an ID with a ReactNode so we can\n * apply widget operations to our list of widgets. It helps us find a ReactNode with a particular\n * ID for relative widget operations.\n */\nexport interface IdentifiedWidget {\n id: string,\n role?: string,\n node: ReactNode,\n}\n\nexport interface WidgetList extends Array<ReactNode> {\n identified: IdentifiedWidget[],\n byId(id: string): ReactNode[],\n withoutId(id: string): ReactNode[],\n byRole(role: string): ReactNode[],\n withoutRole(role: string): ReactNode[],\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import { SlotOperation } from '../types';
|
|
3
|
-
import { WidgetAbsoluteOperation, WidgetAppendOperation, WidgetElementProps, WidgetIdentityProps, WidgetInsertAfterOperation, WidgetInsertBeforeOperation, WidgetOperation, WidgetOperationTypes, WidgetOptionsOperation, WidgetPrependOperation, WidgetRemoveOperation, WidgetRendererOperation, WidgetReplaceOperation } from './types';
|
|
3
|
+
import { WidgetAbsoluteOperation, WidgetAppendOperation, WidgetElementProps, WidgetIdentityProps, WidgetInsertAfterOperation, WidgetInsertBeforeOperation, WidgetList, WidgetOperation, WidgetOperationTypes, WidgetOptionsOperation, WidgetPrependOperation, WidgetRemoveOperation, WidgetRendererOperation, WidgetReplaceOperation } from './types';
|
|
4
4
|
export declare function isWidgetOperation(operation: SlotOperation): operation is WidgetOperation;
|
|
5
5
|
export declare function isWidgetAbsoluteOperation(operation: WidgetOperation): operation is WidgetAbsoluteOperation;
|
|
6
6
|
export declare function isWidgetRelativeOperation(operation: WidgetOperation): operation is (WidgetInsertAfterOperation | WidgetInsertBeforeOperation);
|
|
@@ -19,4 +19,4 @@ export declare function isWidgetIdentityRoleOperation(operation: SlotOperation):
|
|
|
19
19
|
export declare function createWidgetAppendOperation(id: string, slotId: string, element: ReactNode): (import("./types").BaseWidgetOperation & WidgetIdentityProps & WidgetElementProps & {
|
|
20
20
|
op: WidgetOperationTypes.APPEND;
|
|
21
21
|
}) | undefined;
|
|
22
|
-
export declare function createWidgets(operations: WidgetOperation[], componentProps?: Record<string, unknown>):
|
|
22
|
+
export declare function createWidgets(operations: WidgetOperation[], componentProps?: Record<string, unknown>): WidgetList;
|
|
@@ -90,6 +90,7 @@ function createIdentifiedWidget(operation, componentProps) {
|
|
|
90
90
|
}
|
|
91
91
|
return {
|
|
92
92
|
id,
|
|
93
|
+
role: operation.role,
|
|
93
94
|
node: (_jsx(WidgetProvider, { slotId: operation.slotId, widgetId: operation.id, role: operation.role, children: widget }, id)),
|
|
94
95
|
};
|
|
95
96
|
}
|
|
@@ -136,6 +137,24 @@ function removeWidget(operation, widgets) {
|
|
|
136
137
|
widgets.splice(relatedIndex, 1);
|
|
137
138
|
}
|
|
138
139
|
}
|
|
140
|
+
function createWidgetList(identifiedWidgets) {
|
|
141
|
+
const nodes = identifiedWidgets.map(widget => widget.node);
|
|
142
|
+
const widgetList = nodes;
|
|
143
|
+
widgetList.identified = identifiedWidgets;
|
|
144
|
+
widgetList.byId = (id) => {
|
|
145
|
+
return identifiedWidgets.filter(w => w.id === id).map(w => w.node);
|
|
146
|
+
};
|
|
147
|
+
widgetList.withoutId = (id) => {
|
|
148
|
+
return identifiedWidgets.filter(w => w.id !== id).map(w => w.node);
|
|
149
|
+
};
|
|
150
|
+
widgetList.byRole = (role) => {
|
|
151
|
+
return identifiedWidgets.filter(w => w.role === role).map(w => w.node);
|
|
152
|
+
};
|
|
153
|
+
widgetList.withoutRole = (role) => {
|
|
154
|
+
return identifiedWidgets.filter(w => w.role !== role).map(w => w.node);
|
|
155
|
+
};
|
|
156
|
+
return widgetList;
|
|
157
|
+
}
|
|
139
158
|
export function createWidgets(operations, componentProps) {
|
|
140
159
|
const identifiedWidgets = [];
|
|
141
160
|
for (const operation of operations) {
|
|
@@ -160,7 +179,6 @@ export function createWidgets(operations, componentProps) {
|
|
|
160
179
|
}
|
|
161
180
|
}
|
|
162
181
|
}
|
|
163
|
-
|
|
164
|
-
return identifiedWidgets.map(widget => widget.node);
|
|
182
|
+
return createWidgetList(identifiedWidgets);
|
|
165
183
|
}
|
|
166
184
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../runtime/slots/widget/utils.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,iCAAiC,EAAE,MAAM,UAAU,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAgO,oBAAoB,E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AAiB,EAAE,cAAc,CAAC,CAAC;YAC9D,CAAC;iBAAM,IAAI,4BAA4B,CAAC,SAAS,CAAC,EAAE,CAAC;gBACnD,iBAAiB,CAAC,SAAS,EAAE,iBAAiB,EAAE,cAAc,CAAC,CAAC;YAClE,CAAC;iBAAM,IAAI,6BAA6B,CAAC,SAAS,CAAC,EAAE,CAAC;gBACpD,kBAAkB,CAAC,SAAS,EAAE,iBAAiB,EAAE,cAAc,CAAC,CAAC;YACnE,CAAC;iBAAM,IAAI,wBAAwB,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC/C,aAAa,CAAC,SAAS,EAAE,iBAAiB,EAAE,cAAc,CAAC,CAAC;YAC9D,CAAC;iBAAM,IAAI,uBAAuB,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC9C,YAAY,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC;YAC7C,CAAC;QACH,CAAC;IACH,CAAC;IAED,sDAAsD;IACtD,OAAO,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AACtD,CAAC","sourcesContent":["import { ReactNode } from 'react';\nimport { SlotOperation } from '../types';\nimport { isSlotOperationConditionSatisfied } from '../utils';\nimport { IFrameWidget } from './iframe';\nimport { IdentifiedWidget, WidgetAbsoluteOperation, WidgetAppendOperation, WidgetComponentProps, WidgetElementProps, WidgetIdentityProps, WidgetIFrameProps, WidgetInsertAfterOperation, WidgetInsertBeforeOperation, WidgetOperation, WidgetOperationTypes, WidgetOptionsOperation, WidgetPrependOperation, WidgetRemoveOperation, WidgetRendererOperation, WidgetRendererProps, WidgetReplaceOperation } from './types';\nimport WidgetProvider from './WidgetProvider';\n\nexport function isWidgetOperation(operation: SlotOperation): operation is WidgetOperation {\n return Object.values(WidgetOperationTypes).includes(operation.op as WidgetOperationTypes);\n}\n\nexport function isWidgetAbsoluteOperation(operation: WidgetOperation): operation is WidgetAbsoluteOperation {\n return operation.op === WidgetOperationTypes.APPEND || operation.op === WidgetOperationTypes.PREPEND;\n}\n\nexport function isWidgetRelativeOperation(operation: WidgetOperation): operation is (WidgetInsertAfterOperation | WidgetInsertBeforeOperation) {\n return operation.op === WidgetOperationTypes.INSERT_AFTER || operation.op === WidgetOperationTypes.INSERT_BEFORE;\n}\n\nexport function isWidgetAppendOperation(operation: SlotOperation): operation is WidgetAppendOperation {\n return isWidgetOperation(operation) && operation.op === WidgetOperationTypes.APPEND;\n}\n\nexport function isWidgetInsertAfterOperation(operation: SlotOperation): operation is WidgetInsertAfterOperation {\n return isWidgetOperation(operation) && operation.op === WidgetOperationTypes.INSERT_AFTER;\n}\n\nexport function isWidgetInsertBeforeOperation(operation: SlotOperation): operation is WidgetInsertBeforeOperation {\n return isWidgetOperation(operation) && operation.op === WidgetOperationTypes.INSERT_BEFORE;\n}\n\nexport function isWidgetPrependOperation(operation: SlotOperation): operation is WidgetPrependOperation {\n return isWidgetOperation(operation) && operation.op === WidgetOperationTypes.PREPEND;\n}\n\nexport function isWidgetRemoveOperation(operation: SlotOperation): operation is WidgetRemoveOperation {\n return isWidgetOperation(operation) && operation.op === WidgetOperationTypes.REMOVE;\n}\n\nexport function isWidgetReplaceOperation(operation: SlotOperation): operation is WidgetReplaceOperation {\n return isWidgetOperation(operation) && operation.op === WidgetOperationTypes.REPLACE;\n}\n\nexport function isWidgetOptionsOperation(operation: SlotOperation): operation is WidgetOptionsOperation {\n return isWidgetOperation(operation) && operation.op === WidgetOperationTypes.OPTIONS;\n}\n\nexport function isWidgetRendererOperation(operation: SlotOperation): operation is WidgetRendererOperation {\n return isWidgetOperation(operation) && hasWidgetRendererProps(operation);\n}\n\nexport function isWidgetIdentityOperation(operation: SlotOperation): operation is (WidgetOperation & WidgetIdentityProps) {\n return isWidgetOperation(operation) && hasWidgetIdentityProps(operation);\n}\n\nexport function isWidgetIdentityRoleOperation(operation: SlotOperation): operation is (WidgetOperation & WidgetIdentityProps & { role: string }) {\n return isWidgetIdentityOperation(operation) && hasWidgetIdentityRoleProps(operation);\n}\n\nexport function createWidgetAppendOperation(id: string, slotId: string, element: ReactNode) {\n let operation: WidgetOperation | undefined = undefined;\n if (element) {\n operation = {\n slotId,\n id,\n op: WidgetOperationTypes.APPEND,\n element\n };\n }\n\n return operation;\n}\n\n// Widget Operation props helpers\n\nfunction hasWidgetComponentProps(operation: WidgetOperation): operation is (WidgetOperation & WidgetComponentProps) {\n return isWidgetOperation(operation) && 'component' in operation;\n}\n\nfunction hasWidgetElementProps(operation: WidgetOperation): operation is (WidgetOperation & WidgetElementProps) {\n return isWidgetOperation(operation) && 'element' in operation;\n}\n\nfunction hasWidgetIFrameProps(operation: WidgetOperation): operation is (WidgetOperation & WidgetIFrameProps) {\n return isWidgetOperation(operation) && 'url' in operation && 'title' in operation;\n}\n\nfunction hasWidgetRendererProps(operation: WidgetOperation): operation is (WidgetOperation & WidgetRendererProps) {\n return hasWidgetComponentProps(operation) || hasWidgetElementProps(operation) || hasWidgetIFrameProps(operation);\n}\n\nfunction hasWidgetIdentityProps(operation: WidgetOperation): operation is (WidgetOperation & WidgetIdentityProps) {\n return isWidgetOperation(operation) && 'id' in operation;\n}\n\nfunction hasWidgetIdentityRoleProps(operation: WidgetOperation): operation is (WidgetOperation & WidgetIdentityProps & { role: string }) {\n return hasWidgetIdentityProps(operation) && 'role' in operation;\n}\n\n/**\n * An 'identified' widget just means a data structure with an ID and a ReactNode.\n */\nfunction createIdentifiedWidget(operation: WidgetRendererOperation, componentProps?: Record<string, unknown>) {\n let widget: ReactNode = null;\n const { id } = operation;\n if (hasWidgetComponentProps(operation)) {\n widget = (\n <operation.component {...componentProps} />\n );\n } else if (hasWidgetElementProps(operation)) {\n widget = operation.element;\n } else if (hasWidgetIFrameProps(operation)) {\n widget = (\n <IFrameWidget url={operation.url} title={operation.title} />\n );\n }\n\n return {\n id,\n node: (\n <WidgetProvider key={id} slotId={operation.slotId} widgetId={operation.id} role={operation.role}>\n {widget}\n </WidgetProvider>\n ),\n };\n}\n\nfunction findRelatedWidgetIndex(id: string, widgets: IdentifiedWidget[]) {\n for (const candidateRelatedWidget of widgets) {\n if (candidateRelatedWidget.id === id) {\n return widgets.indexOf(candidateRelatedWidget);\n }\n }\n return null;\n}\n\nfunction appendWidget(operation: WidgetAppendOperation, widgets: IdentifiedWidget[], componentProps?: Record<string, unknown>) {\n const widget = createIdentifiedWidget(operation, componentProps);\n widgets.push(widget);\n}\n\nfunction prependWidget(operation: WidgetPrependOperation, widgets: IdentifiedWidget[], componentProps?: Record<string, unknown>) {\n const widget = createIdentifiedWidget(operation, componentProps);\n widgets.unshift(widget);\n}\n\nfunction insertAfterWidget(operation: WidgetInsertAfterOperation, widgets: IdentifiedWidget[], componentProps?: Record<string, unknown>) {\n const widget = createIdentifiedWidget(operation, componentProps);\n const relatedIndex = findRelatedWidgetIndex(operation.relatedId, widgets);\n if (relatedIndex !== null) {\n widgets.splice(relatedIndex + 1, 0, widget);\n }\n}\n\nfunction insertBeforeWidget(operation: WidgetInsertBeforeOperation, widgets: IdentifiedWidget[], componentProps?: Record<string, unknown>) {\n const widget = createIdentifiedWidget(operation, componentProps);\n const relatedIndex = findRelatedWidgetIndex(operation.relatedId, widgets);\n if (relatedIndex !== null) {\n widgets.splice(relatedIndex, 0, widget);\n }\n}\n\nfunction replaceWidget(operation: WidgetReplaceOperation, widgets: IdentifiedWidget[], componentProps?: Record<string, unknown>) {\n const widget = createIdentifiedWidget(operation, componentProps);\n const relatedIndex = findRelatedWidgetIndex(operation.relatedId, widgets);\n if (relatedIndex !== null) {\n widgets.splice(relatedIndex, 1, widget);\n }\n}\n\nfunction removeWidget(operation: WidgetRemoveOperation, widgets: IdentifiedWidget[]) {\n const relatedIndex = findRelatedWidgetIndex(operation.relatedId, widgets);\n if (relatedIndex !== null) {\n widgets.splice(relatedIndex, 1);\n }\n}\n\nexport function createWidgets(operations: WidgetOperation[], componentProps?: Record<string, unknown>) {\n const identifiedWidgets: IdentifiedWidget[] = [];\n\n for (const operation of operations) {\n if (isSlotOperationConditionSatisfied(operation)) {\n if (isWidgetAppendOperation(operation)) {\n appendWidget(operation, identifiedWidgets, componentProps);\n } else if (isWidgetPrependOperation(operation)) {\n prependWidget(operation, identifiedWidgets, componentProps);\n } else if (isWidgetInsertAfterOperation(operation)) {\n insertAfterWidget(operation, identifiedWidgets, componentProps);\n } else if (isWidgetInsertBeforeOperation(operation)) {\n insertBeforeWidget(operation, identifiedWidgets, componentProps);\n } else if (isWidgetReplaceOperation(operation)) {\n replaceWidget(operation, identifiedWidgets, componentProps);\n } else if (isWidgetRemoveOperation(operation)) {\n removeWidget(operation, identifiedWidgets);\n }\n }\n }\n\n // Remove the 'id' metadata and return just the nodes.\n return identifiedWidgets.map(widget => widget.node);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../runtime/slots/widget/utils.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,iCAAiC,EAAE,MAAM,UAAU,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAA4O,oBAAoB,EAA+I,MAAM,SAAS,CAAC;AACta,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C,MAAM,UAAU,iBAAiB,CAAC,SAAwB;IACxD,OAAO,MAAM,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,EAA0B,CAAC,CAAC;AAC5F,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,SAA0B;IAClE,OAAO,SAAS,CAAC,EAAE,KAAK,oBAAoB,CAAC,MAAM,IAAI,SAAS,CAAC,EAAE,KAAK,oBAAoB,CAAC,OAAO,CAAC;AACvG,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,SAA0B;IAClE,OAAO,SAAS,CAAC,EAAE,KAAK,oBAAoB,CAAC,YAAY,IAAI,SAAS,CAAC,EAAE,KAAK,oBAAoB,CAAC,aAAa,CAAC;AACnH,CAAC;AAED,MAAM,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AAiB,CAAC,CAAC;YAC7C,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["import { ReactNode } from 'react';\nimport { SlotOperation } from '../types';\nimport { isSlotOperationConditionSatisfied } from '../utils';\nimport { IFrameWidget } from './iframe';\nimport { IdentifiedWidget, WidgetAbsoluteOperation, WidgetAppendOperation, WidgetComponentProps, WidgetElementProps, WidgetIdentityProps, WidgetIFrameProps, WidgetInsertAfterOperation, WidgetInsertBeforeOperation, WidgetList, WidgetOperation, WidgetOperationTypes, WidgetOptionsOperation, WidgetPrependOperation, WidgetRemoveOperation, WidgetRendererOperation, WidgetRendererProps, WidgetReplaceOperation } from './types';\nimport WidgetProvider from './WidgetProvider';\n\nexport function isWidgetOperation(operation: SlotOperation): operation is WidgetOperation {\n return Object.values(WidgetOperationTypes).includes(operation.op as WidgetOperationTypes);\n}\n\nexport function isWidgetAbsoluteOperation(operation: WidgetOperation): operation is WidgetAbsoluteOperation {\n return operation.op === WidgetOperationTypes.APPEND || operation.op === WidgetOperationTypes.PREPEND;\n}\n\nexport function isWidgetRelativeOperation(operation: WidgetOperation): operation is (WidgetInsertAfterOperation | WidgetInsertBeforeOperation) {\n return operation.op === WidgetOperationTypes.INSERT_AFTER || operation.op === WidgetOperationTypes.INSERT_BEFORE;\n}\n\nexport function isWidgetAppendOperation(operation: SlotOperation): operation is WidgetAppendOperation {\n return isWidgetOperation(operation) && operation.op === WidgetOperationTypes.APPEND;\n}\n\nexport function isWidgetInsertAfterOperation(operation: SlotOperation): operation is WidgetInsertAfterOperation {\n return isWidgetOperation(operation) && operation.op === WidgetOperationTypes.INSERT_AFTER;\n}\n\nexport function isWidgetInsertBeforeOperation(operation: SlotOperation): operation is WidgetInsertBeforeOperation {\n return isWidgetOperation(operation) && operation.op === WidgetOperationTypes.INSERT_BEFORE;\n}\n\nexport function isWidgetPrependOperation(operation: SlotOperation): operation is WidgetPrependOperation {\n return isWidgetOperation(operation) && operation.op === WidgetOperationTypes.PREPEND;\n}\n\nexport function isWidgetRemoveOperation(operation: SlotOperation): operation is WidgetRemoveOperation {\n return isWidgetOperation(operation) && operation.op === WidgetOperationTypes.REMOVE;\n}\n\nexport function isWidgetReplaceOperation(operation: SlotOperation): operation is WidgetReplaceOperation {\n return isWidgetOperation(operation) && operation.op === WidgetOperationTypes.REPLACE;\n}\n\nexport function isWidgetOptionsOperation(operation: SlotOperation): operation is WidgetOptionsOperation {\n return isWidgetOperation(operation) && operation.op === WidgetOperationTypes.OPTIONS;\n}\n\nexport function isWidgetRendererOperation(operation: SlotOperation): operation is WidgetRendererOperation {\n return isWidgetOperation(operation) && hasWidgetRendererProps(operation);\n}\n\nexport function isWidgetIdentityOperation(operation: SlotOperation): operation is (WidgetOperation & WidgetIdentityProps) {\n return isWidgetOperation(operation) && hasWidgetIdentityProps(operation);\n}\n\nexport function isWidgetIdentityRoleOperation(operation: SlotOperation): operation is (WidgetOperation & WidgetIdentityProps & { role: string }) {\n return isWidgetIdentityOperation(operation) && hasWidgetIdentityRoleProps(operation);\n}\n\nexport function createWidgetAppendOperation(id: string, slotId: string, element: ReactNode) {\n let operation: WidgetOperation | undefined = undefined;\n if (element) {\n operation = {\n slotId,\n id,\n op: WidgetOperationTypes.APPEND,\n element\n };\n }\n\n return operation;\n}\n\n// Widget Operation props helpers\n\nfunction hasWidgetComponentProps(operation: WidgetOperation): operation is (WidgetOperation & WidgetComponentProps) {\n return isWidgetOperation(operation) && 'component' in operation;\n}\n\nfunction hasWidgetElementProps(operation: WidgetOperation): operation is (WidgetOperation & WidgetElementProps) {\n return isWidgetOperation(operation) && 'element' in operation;\n}\n\nfunction hasWidgetIFrameProps(operation: WidgetOperation): operation is (WidgetOperation & WidgetIFrameProps) {\n return isWidgetOperation(operation) && 'url' in operation && 'title' in operation;\n}\n\nfunction hasWidgetRendererProps(operation: WidgetOperation): operation is (WidgetOperation & WidgetRendererProps) {\n return hasWidgetComponentProps(operation) || hasWidgetElementProps(operation) || hasWidgetIFrameProps(operation);\n}\n\nfunction hasWidgetIdentityProps(operation: WidgetOperation): operation is (WidgetOperation & WidgetIdentityProps) {\n return isWidgetOperation(operation) && 'id' in operation;\n}\n\nfunction hasWidgetIdentityRoleProps(operation: WidgetOperation): operation is (WidgetOperation & WidgetIdentityProps & { role: string }) {\n return hasWidgetIdentityProps(operation) && 'role' in operation;\n}\n\n/**\n * An 'identified' widget just means a data structure with an ID and a ReactNode.\n */\nfunction createIdentifiedWidget(operation: WidgetRendererOperation, componentProps?: Record<string, unknown>) {\n let widget: ReactNode = null;\n const { id } = operation;\n if (hasWidgetComponentProps(operation)) {\n widget = (\n <operation.component {...componentProps} />\n );\n } else if (hasWidgetElementProps(operation)) {\n widget = operation.element;\n } else if (hasWidgetIFrameProps(operation)) {\n widget = (\n <IFrameWidget url={operation.url} title={operation.title} />\n );\n }\n\n return {\n id,\n role: operation.role,\n node: (\n <WidgetProvider key={id} slotId={operation.slotId} widgetId={operation.id} role={operation.role}>\n {widget}\n </WidgetProvider>\n ),\n };\n}\n\nfunction findRelatedWidgetIndex(id: string, widgets: IdentifiedWidget[]) {\n for (const candidateRelatedWidget of widgets) {\n if (candidateRelatedWidget.id === id) {\n return widgets.indexOf(candidateRelatedWidget);\n }\n }\n return null;\n}\n\nfunction appendWidget(operation: WidgetAppendOperation, widgets: IdentifiedWidget[], componentProps?: Record<string, unknown>) {\n const widget = createIdentifiedWidget(operation, componentProps);\n widgets.push(widget);\n}\n\nfunction prependWidget(operation: WidgetPrependOperation, widgets: IdentifiedWidget[], componentProps?: Record<string, unknown>) {\n const widget = createIdentifiedWidget(operation, componentProps);\n widgets.unshift(widget);\n}\n\nfunction insertAfterWidget(operation: WidgetInsertAfterOperation, widgets: IdentifiedWidget[], componentProps?: Record<string, unknown>) {\n const widget = createIdentifiedWidget(operation, componentProps);\n const relatedIndex = findRelatedWidgetIndex(operation.relatedId, widgets);\n if (relatedIndex !== null) {\n widgets.splice(relatedIndex + 1, 0, widget);\n }\n}\n\nfunction insertBeforeWidget(operation: WidgetInsertBeforeOperation, widgets: IdentifiedWidget[], componentProps?: Record<string, unknown>) {\n const widget = createIdentifiedWidget(operation, componentProps);\n const relatedIndex = findRelatedWidgetIndex(operation.relatedId, widgets);\n if (relatedIndex !== null) {\n widgets.splice(relatedIndex, 0, widget);\n }\n}\n\nfunction replaceWidget(operation: WidgetReplaceOperation, widgets: IdentifiedWidget[], componentProps?: Record<string, unknown>) {\n const widget = createIdentifiedWidget(operation, componentProps);\n const relatedIndex = findRelatedWidgetIndex(operation.relatedId, widgets);\n if (relatedIndex !== null) {\n widgets.splice(relatedIndex, 1, widget);\n }\n}\n\nfunction removeWidget(operation: WidgetRemoveOperation, widgets: IdentifiedWidget[]) {\n const relatedIndex = findRelatedWidgetIndex(operation.relatedId, widgets);\n if (relatedIndex !== null) {\n widgets.splice(relatedIndex, 1);\n }\n}\n\nfunction createWidgetList(identifiedWidgets: IdentifiedWidget[]): WidgetList {\n const nodes = identifiedWidgets.map(widget => widget.node);\n const widgetList = nodes as WidgetList;\n\n widgetList.identified = identifiedWidgets;\n\n widgetList.byId = (id: string): ReactNode[] => {\n return identifiedWidgets.filter(w => w.id === id).map(w => w.node);\n };\n\n widgetList.withoutId = (id: string): ReactNode[] => {\n return identifiedWidgets.filter(w => w.id !== id).map(w => w.node);\n };\n\n widgetList.byRole = (role: string): ReactNode[] => {\n return identifiedWidgets.filter(w => w.role === role).map(w => w.node);\n };\n\n widgetList.withoutRole = (role: string): ReactNode[] => {\n return identifiedWidgets.filter(w => w.role !== role).map(w => w.node);\n };\n\n return widgetList;\n}\n\nexport function createWidgets(operations: WidgetOperation[], componentProps?: Record<string, unknown>): WidgetList {\n const identifiedWidgets: IdentifiedWidget[] = [];\n\n for (const operation of operations) {\n if (isSlotOperationConditionSatisfied(operation)) {\n if (isWidgetAppendOperation(operation)) {\n appendWidget(operation, identifiedWidgets, componentProps);\n } else if (isWidgetPrependOperation(operation)) {\n prependWidget(operation, identifiedWidgets, componentProps);\n } else if (isWidgetInsertAfterOperation(operation)) {\n insertAfterWidget(operation, identifiedWidgets, componentProps);\n } else if (isWidgetInsertBeforeOperation(operation)) {\n insertBeforeWidget(operation, identifiedWidgets, componentProps);\n } else if (isWidgetReplaceOperation(operation)) {\n replaceWidget(operation, identifiedWidgets, componentProps);\n } else if (isWidgetRemoveOperation(operation)) {\n removeWidget(operation, identifiedWidgets);\n }\n }\n }\n\n return createWidgetList(identifiedWidgets);\n}\n"]}
|
|
@@ -4,9 +4,9 @@ import { useIntl } from '../../../runtime';
|
|
|
4
4
|
import { getUrlByRouteRole } from '../../../runtime/routing';
|
|
5
5
|
import messages from './messages';
|
|
6
6
|
export default function HomePage() {
|
|
7
|
-
const coursewareUrl = getUrlByRouteRole('courseware');
|
|
8
|
-
const dashboardUrl = getUrlByRouteRole('
|
|
9
|
-
const slotShowcaseUrl = getUrlByRouteRole('slotShowcase');
|
|
7
|
+
const coursewareUrl = getUrlByRouteRole('org.openedx.frontend.role.courseware');
|
|
8
|
+
const dashboardUrl = getUrlByRouteRole('org.openedx.frontend.role.dashboard');
|
|
9
|
+
const slotShowcaseUrl = getUrlByRouteRole('org.openedx.frontend.role.slotShowcase');
|
|
10
10
|
const intl = useIntl();
|
|
11
11
|
return (_jsxs("div", { className: "p-3", children: [_jsx("p", { children: intl.formatMessage(messages.homeContent) }), _jsxs("ul", { children: [coursewareUrl !== null && (_jsx("li", { children: _jsx(Link, { to: coursewareUrl, children: "Go to courseware page" }) })), dashboardUrl !== null && (_jsx("li", { children: _jsx(Link, { to: dashboardUrl, children: "Go to dashboard page" }) })), slotShowcaseUrl !== null && (_jsx("li", { children: _jsx(Link, { to: slotShowcaseUrl, children: "Go to slot showcase page" }) }))] })] }));
|
|
12
12
|
}
|