UNPKG

@carbon/ibm-products

Version:
209 lines (207 loc) 7.24 kB
/** * Copyright IBM Corp. 2020, 2026 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ //#region src/global/js/package-settings.js const defaults = { prefix: "c4p", component: { AboutModal: true, APIKeyModal: true, Cascade: true, Checklist: true, CreateModal: true, CreateFullPage: true, CreateFullPageStep: true, CreateSidePanel: true, CreateTearsheetNarrow: true, CreateTearsheet: true, CreateTearsheetStep: true, CreateTearsheetDivider: true, Datagrid: true, EditInPlace: true, EmptyState: true, ErrorEmptyState: true, ExportModal: true, ExpressiveCard: true, FullPageError: true, HTTPError403: true, HTTPError404: true, HTTPErrorOther: true, ImportModal: true, MultiAddSelect: true, NotificationsPanel: true, NoDataEmptyState: true, NoTagsEmptyState: true, NotFoundEmptyState: true, NotificationsEmptyState: true, OptionsTile: true, PageHeader: true, ProductiveCard: true, RemoveModal: true, Saving: true, SidePanel: true, SingleAddSelect: true, StatusIcon: true, TagSet: true, Tearsheet: true, TearsheetNarrow: true, UnauthorizedEmptyState: true, UserProfileImage: true, WebTerminal: true, WebTerminalContentWrapper: true, WebTerminalProvider: true, UserAvatar: true, Toolbar: false, ToolbarButton: false, ToolbarGroup: false, EditSidePanel: false, CancelableTextEdit: false, DataSpreadsheet: false, EditTearsheet: false, EditTearsheetForm: false, EditTearsheetNarrow: false, EditFullPage: false, EditUpdateCards: false, Nav: false, NavItem: false, NavList: false, BigNumber: false, TruncatedList: false, TruncatedText: false, DelimitedList: false, ScrollGradient: false, StringFormatter: false, StatusIndicator: false, StatusIndicatorStep: false, TagOverflow: false, ActionBar: false, FilterPanel: false, FilterPanelAccordion: false, FilterPanelAccordionItem: false, FilterPanelCheckbox: false, FilterPanelCheckboxWithOverflow: false, FilterPanelGroup: false, FilterPanelLabel: false, FilterPanelSearch: false, ConditionBuilder: false, GetStartedCard: false, Coachmark: false, CoachmarkBeacon: false, CoachmarkButton: false, CoachmarkFixed: false, CoachmarkOverlayElement: false, CoachmarkOverlayElements: false, CoachmarkStack: false, CoachmarkTagline: false, Decorator: false, DecoratorLink: false, DecoratorSingleButton: false, DecoratorDualButton: false, DescriptionList: false, DescriptionListBody: false, DescriptionListCell: false, DescriptionListRow: false, SearchBar: false, EmptyStateV2: false, Guidebanner: false, GuidebannerElement: false, GuidebannerElementButton: false, GuidebannerElementLink: false, InlineTip: false, InlineTipButton: false, InlineTipLink: false, InterstitialScreen: true, NonLinearReading: false }, feature: { "default-portal-target-body": true, "Datagrid.useInlineEdit": false, "Datagrid.useEditableCell": false, "Datagrid.useCustomizeColumns": false, "ExampleComponent.secondaryIcon": false, "ExampleComponent.useExample": false } }; const componentFlagDeprecationNote = "The component feature flag (canary) mechanism is deprecated and will be removed in a future release. Components are now published with a PDLC status prefix and can be imported directly, e.g. `import { previewCandidate__ComponentName } from \"@carbon/ibm-products\"`. See https://carbondesignsystem.com/contributing/product-development-lifecycle/"; const warningMessageComponent = (property) => `Carbon for IBM Products (WARNING): Component "${property}" enabled via feature flags. This component has not yet completed its review process.\nCarbon for IBM Products (DEPRECATION): ${componentFlagDeprecationNote}`; const warningMessageFeature = (property) => `Carbon for IBM Products (WARNING): Feature "${property}" enabled via feature flags.`; const errorMessageFeature = (property) => `Carbon for IBM Products (Error): Feature "${property}" not enabled. To enable see the notes on feature flags in the README.`; const warningMessageAllComponents = `Carbon for IBM Products (WARNING): All components enabled through use of setAllComponents. This includes components that have not yet completed their review process. Carbon for IBM Products (DEPRECATION): ${componentFlagDeprecationNote}`; const warningMessageAllFeatures = "Carbon for IBM Products (WARNING): All features enabled through use of setAllFeatures"; const all = { INITIAL: (v) => v, ON: () => true, OFF: () => false }; let allComponents = all.INITIAL; let allFeatures = all.INITIAL; let silent = false; const component = new Proxy({ ...defaults.component }, { set(target, property, value) { if (target[property] !== true && !silent && value) console.warn(warningMessageComponent(property)); target[property] = value; return true; }, get(target, property) { return allComponents(target[property] ?? false); } }); const feature = new Proxy({ ...defaults.feature }, { set(target, property, value) { if (!Object.getOwnPropertyDescriptor(defaults.feature, property)) return true; if (target[property] !== true && !silent && value) console.warn(warningMessageFeature(property)); target[property] = value; return true; }, get(target, property) { return allFeatures(target[property] ?? false); } }); const devtoolsAttribute = "data-carbon-devtools-id"; function getDevtoolsId(componentName) { return `${defaults.prefix}--${componentName}`; } var package_settings_default = { devtoolsAttribute, getDevtoolsId, prefix: defaults.prefix, component, feature, isComponentEnabled: (componentOrName, byDefault = false) => { const componentName = componentOrName?.displayName || componentOrName?.name || componentOrName; return byDefault ? defaults.component[componentName] : component[componentName]; }, isComponentPublic: (componentOrName, byDefault = false) => { const componentName = componentOrName?.displayName || componentOrName?.name || componentOrName; return Object.prototype.hasOwnProperty.call(byDefault ? defaults.component : component, componentName); }, isFeatureEnabled: (featureName, byDefault = false) => { return byDefault ? defaults.feature[featureName] : feature[featureName]; }, checkReportFeatureEnabled(featureName) { if (feature[featureName]) return true; else console.error(errorMessageFeature(featureName)); }, isFeaturePublic: (featureName, byDefault = false) => { return Object.prototype.hasOwnProperty.call(byDefault ? defaults.feature : feature, featureName); }, setAllComponents: (enabled) => { enabled === true && !silent && console.warn(warningMessageAllComponents); allComponents = enabled === true ? all.ON : enabled === false ? all.OFF : all.INITIAL; }, setAllFeatures: (enabled) => { enabled === true && !silent && console.warn(warningMessageAllFeatures); allFeatures = enabled === true ? all.ON : enabled === false ? all.OFF : all.INITIAL; }, _silenceWarnings: (value) => { silent = value; } }; //#endregion exports.default = package_settings_default; exports.devtoolsAttribute = devtoolsAttribute; exports.getDevtoolsId = getDevtoolsId;