@strapi/content-manager 5.45.0 → 5.46.0
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/admin/content-manager.js +26 -2
- package/dist/admin/content-manager.js.map +1 -1
- package/dist/admin/content-manager.mjs +26 -2
- package/dist/admin/content-manager.mjs.map +1 -1
- package/dist/admin/hooks/useContentTypeSchema.js +4 -1
- package/dist/admin/hooks/useContentTypeSchema.js.map +1 -1
- package/dist/admin/hooks/useContentTypeSchema.mjs +4 -1
- package/dist/admin/hooks/useContentTypeSchema.mjs.map +1 -1
- package/dist/admin/hooks/useDocumentLayout.js +67 -45
- package/dist/admin/hooks/useDocumentLayout.js.map +1 -1
- package/dist/admin/hooks/useDocumentLayout.mjs +67 -45
- package/dist/admin/hooks/useDocumentLayout.mjs.map +1 -1
- package/dist/admin/hooks/usePersistentQueryParams.js +4 -1
- package/dist/admin/hooks/usePersistentQueryParams.js.map +1 -1
- package/dist/admin/hooks/usePersistentQueryParams.mjs +4 -1
- package/dist/admin/hooks/usePersistentQueryParams.mjs.map +1 -1
- package/dist/admin/pages/ComponentConfigurationPage.js +7 -3
- package/dist/admin/pages/ComponentConfigurationPage.js.map +1 -1
- package/dist/admin/pages/ComponentConfigurationPage.mjs +7 -3
- package/dist/admin/pages/ComponentConfigurationPage.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/Code.js +21 -4
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/Code.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/Code.mjs +19 -2
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/Code.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/Link.mjs +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.js +9 -6
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.mjs +10 -7
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.js +1 -34
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.mjs +3 -35
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksToolbar.js +33 -18
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksToolbar.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksToolbar.mjs +34 -19
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksToolbar.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/DefaultBlocksStore.js +22 -0
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/DefaultBlocksStore.js.map +1 -0
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/DefaultBlocksStore.mjs +20 -0
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/DefaultBlocksStore.mjs.map +1 -0
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/ComponentCategory.js +15 -4
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/ComponentCategory.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/ComponentCategory.mjs +16 -5
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/ComponentCategory.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.js +26 -4
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.mjs +26 -4
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/Field.js +31 -0
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/Field.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/Field.mjs +31 -0
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/Field.mjs.map +1 -1
- package/dist/admin/preview/components/InputPopover.js +3 -0
- package/dist/admin/preview/components/InputPopover.js.map +1 -1
- package/dist/admin/preview/components/InputPopover.mjs +3 -0
- package/dist/admin/preview/components/InputPopover.mjs.map +1 -1
- package/dist/admin/preview/hooks/usePreviewInputManager.js +24 -0
- package/dist/admin/preview/hooks/usePreviewInputManager.js.map +1 -1
- package/dist/admin/preview/hooks/usePreviewInputManager.mjs +24 -0
- package/dist/admin/preview/hooks/usePreviewInputManager.mjs.map +1 -1
- package/dist/admin/preview/utils/previewScript.js +616 -78
- package/dist/admin/preview/utils/previewScript.js.map +1 -1
- package/dist/admin/preview/utils/previewScript.mjs +616 -78
- package/dist/admin/preview/utils/previewScript.mjs.map +1 -1
- package/dist/admin/src/content-manager.d.ts +26 -0
- package/dist/admin/src/exports.d.ts +1 -0
- package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.d.ts +14 -8
- package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/DefaultBlocksStore.d.ts +3 -0
- package/dist/admin/src/pages/EditView/components/FormInputs/DynamicZone/ComponentCard.d.ts +1 -1
- package/dist/admin/src/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.d.ts +11 -1
- package/dist/server/homepage/services/homepage.js +12 -8
- package/dist/server/homepage/services/homepage.js.map +1 -1
- package/dist/server/homepage/services/homepage.mjs +12 -8
- package/dist/server/homepage/services/homepage.mjs.map +1 -1
- package/dist/server/services/metrics.js +1 -5
- package/dist/server/services/metrics.js.map +1 -1
- package/dist/server/services/metrics.mjs +1 -5
- package/dist/server/services/metrics.mjs.map +1 -1
- package/dist/server/src/homepage/services/homepage.d.ts.map +1 -1
- package/dist/server/src/services/metrics.d.ts.map +1 -1
- package/package.json +6 -6
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var InjectionZone = require('./components/InjectionZone.js');
|
|
4
4
|
var plugin = require('./constants/plugin.js');
|
|
5
5
|
var DocumentActions = require('./pages/EditView/components/DocumentActions.js');
|
|
6
|
+
var DefaultBlocksStore = require('./pages/EditView/components/FormInputs/BlocksInput/DefaultBlocksStore.js');
|
|
6
7
|
var Header = require('./pages/EditView/components/Header.js');
|
|
7
8
|
var Panels = require('./pages/EditView/components/Panels.js');
|
|
8
9
|
var Actions = require('./pages/ListView/components/BulkActions/Actions.js');
|
|
@@ -11,6 +12,22 @@ var TableActions = require('./pages/ListView/components/TableActions.js');
|
|
|
11
12
|
/* -------------------------------------------------------------------------------------------------
|
|
12
13
|
* ContentManager plugin
|
|
13
14
|
* -----------------------------------------------------------------------------------------------*/ class ContentManagerPlugin {
|
|
15
|
+
addRichTextBlocks(blocks) {
|
|
16
|
+
if (typeof blocks === 'function') {
|
|
17
|
+
const result = blocks(this.richTextBlocksStore);
|
|
18
|
+
if (typeof result !== 'object' || result === null) {
|
|
19
|
+
throw new Error(`Expected the \`blocks\` passed to \`addRichTextBlocks\` to be an object or a function, but received ${getPrintableType(result)}`);
|
|
20
|
+
}
|
|
21
|
+
this.richTextBlocksStore = result;
|
|
22
|
+
} else if (typeof blocks === 'object') {
|
|
23
|
+
this.richTextBlocksStore = {
|
|
24
|
+
...this.richTextBlocksStore,
|
|
25
|
+
...blocks
|
|
26
|
+
};
|
|
27
|
+
} else {
|
|
28
|
+
throw new Error(`Expected the \`blocks\` passed to \`addRichTextBlocks\` to be an object or a function, but received ${getPrintableType(blocks)}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
14
31
|
addEditViewSidePanel(panels) {
|
|
15
32
|
if (Array.isArray(panels)) {
|
|
16
33
|
this.editViewSidePanels = [
|
|
@@ -69,6 +86,7 @@ var TableActions = require('./pages/ListView/components/TableActions.js');
|
|
|
69
86
|
addDocumentAction: this.addDocumentAction.bind(this),
|
|
70
87
|
addDocumentHeaderAction: this.addDocumentHeaderAction.bind(this),
|
|
71
88
|
addEditViewSidePanel: this.addEditViewSidePanel.bind(this),
|
|
89
|
+
addRichTextBlocks: this.addRichTextBlocks.bind(this),
|
|
72
90
|
getBulkActions: ()=>this.bulkActions,
|
|
73
91
|
getDocumentActions: (position)=>{
|
|
74
92
|
/**
|
|
@@ -87,7 +105,10 @@ var TableActions = require('./pages/ListView/components/TableActions.js');
|
|
|
87
105
|
return this.documentActions;
|
|
88
106
|
},
|
|
89
107
|
getEditViewSidePanels: ()=>this.editViewSidePanels,
|
|
90
|
-
getHeaderActions: ()=>this.headerActions
|
|
108
|
+
getHeaderActions: ()=>this.headerActions,
|
|
109
|
+
getRichTextBlocks: ()=>({
|
|
110
|
+
...this.richTextBlocksStore
|
|
111
|
+
})
|
|
91
112
|
}
|
|
92
113
|
};
|
|
93
114
|
}
|
|
@@ -97,7 +118,10 @@ var TableActions = require('./pages/ListView/components/TableActions.js');
|
|
|
97
118
|
* the content-manager. The function calls however, need to be called at runtime in the
|
|
98
119
|
* application, so instead we collate them and run them later with the complete list incl.
|
|
99
120
|
* ones already registered & the context of the view.
|
|
100
|
-
*/ this.
|
|
121
|
+
*/ this.richTextBlocksStore = {
|
|
122
|
+
...DefaultBlocksStore.defaultBlocksStore
|
|
123
|
+
};
|
|
124
|
+
this.bulkActions = [
|
|
101
125
|
...Actions.DEFAULT_BULK_ACTIONS
|
|
102
126
|
];
|
|
103
127
|
this.documentActions = [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-manager.js","sources":["../../admin/src/content-manager.ts"],"sourcesContent":["/* eslint-disable check-file/filename-naming-convention */\nimport { INJECTION_ZONES } from './components/InjectionZone';\nimport { PLUGIN_ID } from './constants/plugin';\nimport {\n DEFAULT_ACTIONS,\n type DocumentActionPosition,\n type DocumentActionDescription,\n} from './pages/EditView/components/DocumentActions';\nimport {\n DEFAULT_HEADER_ACTIONS,\n type HeaderActionDescription,\n} from './pages/EditView/components/Header';\nimport { ActionsPanel, type PanelDescription } from './pages/EditView/components/Panels';\nimport {\n DEFAULT_BULK_ACTIONS,\n type BulkActionDescription,\n} from './pages/ListView/components/BulkActions/Actions';\nimport { DEFAULT_TABLE_ROW_ACTIONS } from './pages/ListView/components/TableActions';\n\nimport type { Document } from './hooks/useDocument';\nimport type { DocumentMetadata } from '../../shared/contracts/collection-types';\nimport type { DescriptionComponent, PluginConfig } from '@strapi/admin/strapi-admin';\n\n/* -------------------------------------------------------------------------------------------------\n * Configuration Types\n * -----------------------------------------------------------------------------------------------*/\n\ntype DescriptionReducer<Config extends object> = (prev: Config[]) => Config[];\n\ninterface EditViewContext {\n /**\n * This will ONLY be null, if the content-type\n * does not have draft & published enabled.\n */\n activeTab: 'draft' | 'published' | null;\n /**\n * Will be either 'single-types' | 'collection-types'\n */\n collectionType: string;\n /**\n * this will be undefined if someone is creating an entry.\n */\n document?: Document;\n /**\n * this will be undefined if someone is creating an entry.\n */\n documentId?: string;\n /**\n * this will be undefined if someone is creating an entry.\n */\n meta?: DocumentMetadata;\n /**\n * The current content-type's model.\n */\n model: string;\n}\n\ninterface ListViewContext {\n /**\n * Will be either 'single-types' | 'collection-types'\n */\n collectionType: string;\n /**\n * The current selected documents in the table\n */\n documents: Document[];\n /**\n * The current content-type's model.\n */\n model: string;\n}\n\ninterface PanelComponentProps extends EditViewContext {}\n\ninterface PanelComponent extends DescriptionComponent<PanelComponentProps, PanelDescription> {\n /**\n * The defaults are added by Strapi only, if you're providing your own component,\n * you do not need to provide this.\n */\n type?: 'actions' | 'releases';\n}\n\ninterface DocumentActionProps extends EditViewContext {}\n\ninterface DocumentActionComponent\n extends DescriptionComponent<DocumentActionProps, DocumentActionDescription> {\n type?:\n | 'clone'\n | 'configure-the-view'\n | 'delete'\n | 'discard'\n | 'edit'\n | 'edit-the-model'\n | 'history'\n | 'publish'\n | 'unpublish'\n | 'update';\n position?: DocumentActionDescription['position'];\n}\n\ninterface HeaderActionProps extends EditViewContext {}\n\ninterface HeaderActionComponent\n extends DescriptionComponent<HeaderActionProps, HeaderActionDescription> {}\n\ninterface BulkActionComponentProps extends ListViewContext {}\n\ninterface BulkActionComponent\n extends DescriptionComponent<BulkActionComponentProps, BulkActionDescription> {\n type?: 'delete' | 'publish' | 'unpublish';\n}\n\n/* -------------------------------------------------------------------------------------------------\n * ContentManager plugin\n * -----------------------------------------------------------------------------------------------*/\n\nclass ContentManagerPlugin {\n /**\n * The following properties are the stored ones provided by any plugins registering with\n * the content-manager. The function calls however, need to be called at runtime in the\n * application, so instead we collate them and run them later with the complete list incl.\n * ones already registered & the context of the view.\n */\n bulkActions: BulkActionComponent[] = [...DEFAULT_BULK_ACTIONS];\n documentActions: DocumentActionComponent[] = [\n ...DEFAULT_ACTIONS,\n ...DEFAULT_TABLE_ROW_ACTIONS,\n ...DEFAULT_HEADER_ACTIONS,\n ];\n editViewSidePanels: PanelComponent[] = [ActionsPanel];\n headerActions: HeaderActionComponent[] = [];\n\n constructor() {}\n\n addEditViewSidePanel(panels: DescriptionReducer<PanelComponent>): void;\n addEditViewSidePanel(panels: PanelComponent[]): void;\n addEditViewSidePanel(panels: DescriptionReducer<PanelComponent> | PanelComponent[]) {\n if (Array.isArray(panels)) {\n this.editViewSidePanels = [...this.editViewSidePanels, ...panels];\n } else if (typeof panels === 'function') {\n this.editViewSidePanels = panels(this.editViewSidePanels);\n } else {\n throw new Error(\n `Expected the \\`panels\\` passed to \\`addEditViewSidePanel\\` to be an array or a function, but received ${getPrintableType(\n panels\n )}`\n );\n }\n }\n\n addDocumentAction(actions: DescriptionReducer<DocumentActionComponent>): void;\n addDocumentAction(actions: DocumentActionComponent[]): void;\n addDocumentAction(\n actions: DescriptionReducer<DocumentActionComponent> | DocumentActionComponent[]\n ) {\n if (Array.isArray(actions)) {\n this.documentActions = [...this.documentActions, ...actions];\n } else if (typeof actions === 'function') {\n this.documentActions = actions(this.documentActions);\n } else {\n throw new Error(\n `Expected the \\`actions\\` passed to \\`addDocumentAction\\` to be an array or a function, but received ${getPrintableType(\n actions\n )}`\n );\n }\n }\n\n addDocumentHeaderAction(actions: DescriptionReducer<HeaderActionComponent>): void;\n addDocumentHeaderAction(actions: HeaderActionComponent[]): void;\n addDocumentHeaderAction(\n actions: DescriptionReducer<HeaderActionComponent> | HeaderActionComponent[]\n ) {\n if (Array.isArray(actions)) {\n this.headerActions = [...this.headerActions, ...actions];\n } else if (typeof actions === 'function') {\n this.headerActions = actions(this.headerActions);\n } else {\n throw new Error(\n `Expected the \\`actions\\` passed to \\`addDocumentHeaderAction\\` to be an array or a function, but received ${getPrintableType(\n actions\n )}`\n );\n }\n }\n\n addBulkAction(actions: DescriptionReducer<BulkActionComponent>): void;\n addBulkAction(actions: BulkActionComponent[]): void;\n addBulkAction(actions: DescriptionReducer<BulkActionComponent> | BulkActionComponent[]) {\n if (Array.isArray(actions)) {\n this.bulkActions = [...this.bulkActions, ...actions];\n } else if (typeof actions === 'function') {\n this.bulkActions = actions(this.bulkActions);\n } else {\n throw new Error(\n `Expected the \\`actions\\` passed to \\`addBulkAction\\` to be an array or a function, but received ${getPrintableType(\n actions\n )}`\n );\n }\n }\n\n get config() {\n return {\n id: PLUGIN_ID,\n name: 'Content Manager',\n injectionZones: INJECTION_ZONES,\n apis: {\n addBulkAction: this.addBulkAction.bind(this),\n addDocumentAction: this.addDocumentAction.bind(this),\n addDocumentHeaderAction: this.addDocumentHeaderAction.bind(this),\n addEditViewSidePanel: this.addEditViewSidePanel.bind(this),\n getBulkActions: () => this.bulkActions,\n getDocumentActions: (position?: DocumentActionPosition) => {\n /**\n * When possible, pre-filter the actions by the components static position property.\n * This avoids rendering the actions in multiple places where they weren't displayed,\n * which wasn't visible but created issues with useEffect for instance.\n * The response should still be filtered by the position, as the static property is new\n * and not mandatory to avoid a breaking change.\n */\n if (position) {\n return this.documentActions.filter((action) => {\n return action.position == undefined || [action.position].flat().includes(position);\n });\n }\n\n return this.documentActions;\n },\n getEditViewSidePanels: () => this.editViewSidePanels,\n getHeaderActions: () => this.headerActions,\n },\n } satisfies PluginConfig;\n }\n}\n\n/* -------------------------------------------------------------------------------------------------\n * getPrintableType\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Gets the human-friendly printable type name for the given value, for instance it will yield\n * `array` instead of `object`, as the native `typeof` operator would do.\n */\nconst getPrintableType = (value: unknown): string => {\n const nativeType = typeof value;\n\n if (nativeType === 'object') {\n if (value === null) return 'null';\n if (Array.isArray(value)) return 'array';\n if (value instanceof Object && value.constructor.name !== 'Object') {\n return value.constructor.name;\n }\n }\n\n return nativeType;\n};\n\nexport { ContentManagerPlugin };\nexport type {\n EditViewContext,\n ListViewContext,\n BulkActionComponent,\n BulkActionComponentProps,\n BulkActionDescription,\n DescriptionComponent,\n DescriptionReducer,\n PanelComponentProps,\n PanelComponent,\n PanelDescription,\n DocumentActionComponent,\n DocumentActionDescription,\n DocumentActionProps,\n HeaderActionComponent,\n HeaderActionDescription,\n HeaderActionProps,\n};\n"],"names":["ContentManagerPlugin","addEditViewSidePanel","panels","Array","isArray","editViewSidePanels","Error","getPrintableType","addDocumentAction","actions","documentActions","addDocumentHeaderAction","headerActions","addBulkAction","bulkActions","config","id","PLUGIN_ID","name","injectionZones","INJECTION_ZONES","apis","bind","getBulkActions","getDocumentActions","position","filter","action","undefined","flat","includes","getEditViewSidePanels","getHeaderActions","DEFAULT_BULK_ACTIONS","DEFAULT_ACTIONS","DEFAULT_TABLE_ROW_ACTIONS","DEFAULT_HEADER_ACTIONS","ActionsPanel","value","nativeType","Object"],"mappings":";;;;;;;;;;AAgHA;;AAEkG,qGAElG,MAAMA,oBAAAA,CAAAA;AAoBJC,IAAAA,oBAAAA,CAAqBC,MAA6D,EAAE;QAClF,IAAIC,KAAAA,CAAMC,OAAO,CAACF,MAA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;;;;"}
|
|
1
|
+
{"version":3,"file":"content-manager.js","sources":["../../admin/src/content-manager.ts"],"sourcesContent":["/* eslint-disable check-file/filename-naming-convention */\n\nimport { INJECTION_ZONES } from './components/InjectionZone';\nimport { PLUGIN_ID } from './constants/plugin';\nimport {\n DEFAULT_ACTIONS,\n type DocumentActionPosition,\n type DocumentActionDescription,\n} from './pages/EditView/components/DocumentActions';\nimport { RichTextBlocksStore } from './pages/EditView/components/FormInputs/BlocksInput/BlocksEditor';\nimport { defaultBlocksStore } from './pages/EditView/components/FormInputs/BlocksInput/DefaultBlocksStore';\nimport {\n DEFAULT_HEADER_ACTIONS,\n type HeaderActionDescription,\n} from './pages/EditView/components/Header';\nimport { ActionsPanel, type PanelDescription } from './pages/EditView/components/Panels';\nimport {\n DEFAULT_BULK_ACTIONS,\n type BulkActionDescription,\n} from './pages/ListView/components/BulkActions/Actions';\nimport { DEFAULT_TABLE_ROW_ACTIONS } from './pages/ListView/components/TableActions';\n\nimport type { Document } from './hooks/useDocument';\nimport type { DocumentMetadata } from '../../shared/contracts/collection-types';\nimport type { DescriptionComponent, PluginConfig } from '@strapi/admin/strapi-admin';\n\n/* -------------------------------------------------------------------------------------------------\n * Configuration Types\n * -----------------------------------------------------------------------------------------------*/\n\ntype DescriptionReducer<Config extends object> = (prev: Config[]) => Config[];\ntype DescriptionObjReducer<Config extends object> = (prev: Config) => Config;\n\ninterface EditViewContext {\n /**\n * This will ONLY be null, if the content-type\n * does not have draft & published enabled.\n */\n activeTab: 'draft' | 'published' | null;\n /**\n * Will be either 'single-types' | 'collection-types'\n */\n collectionType: string;\n /**\n * this will be undefined if someone is creating an entry.\n */\n document?: Document;\n /**\n * this will be undefined if someone is creating an entry.\n */\n documentId?: string;\n /**\n * this will be undefined if someone is creating an entry.\n */\n meta?: DocumentMetadata;\n /**\n * The current content-type's model.\n */\n model: string;\n}\n\ninterface ListViewContext {\n /**\n * Will be either 'single-types' | 'collection-types'\n */\n collectionType: string;\n /**\n * The current selected documents in the table\n */\n documents: Document[];\n /**\n * The current content-type's model.\n */\n model: string;\n}\n\ninterface PanelComponentProps extends EditViewContext {}\n\ninterface PanelComponent extends DescriptionComponent<PanelComponentProps, PanelDescription> {\n /**\n * The defaults are added by Strapi only, if you're providing your own component,\n * you do not need to provide this.\n */\n type?: 'actions' | 'releases';\n}\n\ninterface DocumentActionProps extends EditViewContext {}\n\ninterface DocumentActionComponent\n extends DescriptionComponent<DocumentActionProps, DocumentActionDescription> {\n type?:\n | 'clone'\n | 'configure-the-view'\n | 'delete'\n | 'discard'\n | 'edit'\n | 'edit-the-model'\n | 'history'\n | 'publish'\n | 'unpublish'\n | 'update';\n position?: DocumentActionDescription['position'];\n}\n\ninterface HeaderActionProps extends EditViewContext {}\n\ninterface HeaderActionComponent\n extends DescriptionComponent<HeaderActionProps, HeaderActionDescription> {}\n\ninterface BulkActionComponentProps extends ListViewContext {}\n\ninterface BulkActionComponent\n extends DescriptionComponent<BulkActionComponentProps, BulkActionDescription> {\n type?: 'delete' | 'publish' | 'unpublish';\n}\n\n/* -------------------------------------------------------------------------------------------------\n * ContentManager plugin\n * -----------------------------------------------------------------------------------------------*/\n\nclass ContentManagerPlugin {\n /**\n * The following properties are the stored ones provided by any plugins registering with\n * the content-manager. The function calls however, need to be called at runtime in the\n * application, so instead we collate them and run them later with the complete list incl.\n * ones already registered & the context of the view.\n */\n richTextBlocksStore: RichTextBlocksStore = { ...defaultBlocksStore };\n bulkActions: BulkActionComponent[] = [...DEFAULT_BULK_ACTIONS];\n documentActions: DocumentActionComponent[] = [\n ...DEFAULT_ACTIONS,\n ...DEFAULT_TABLE_ROW_ACTIONS,\n ...DEFAULT_HEADER_ACTIONS,\n ];\n editViewSidePanels: PanelComponent[] = [ActionsPanel];\n headerActions: HeaderActionComponent[] = [];\n\n constructor() {}\n\n addRichTextBlocks(blocks: RichTextBlocksStore): void;\n addRichTextBlocks(blocks: DescriptionObjReducer<RichTextBlocksStore>): void;\n addRichTextBlocks(blocks: RichTextBlocksStore | DescriptionObjReducer<RichTextBlocksStore>) {\n if (typeof blocks === 'function') {\n const result = blocks(this.richTextBlocksStore);\n if (typeof result !== 'object' || result === null) {\n throw new Error(\n `Expected the \\`blocks\\` passed to \\`addRichTextBlocks\\` to be an object or a function, but received ${getPrintableType(result)}`\n );\n }\n this.richTextBlocksStore = result;\n } else if (typeof blocks === 'object') {\n this.richTextBlocksStore = { ...this.richTextBlocksStore, ...blocks };\n } else {\n throw new Error(\n `Expected the \\`blocks\\` passed to \\`addRichTextBlocks\\` to be an object or a function, but received ${getPrintableType(\n blocks\n )}`\n );\n }\n }\n\n addEditViewSidePanel(panels: DescriptionReducer<PanelComponent>): void;\n addEditViewSidePanel(panels: PanelComponent[]): void;\n addEditViewSidePanel(panels: DescriptionReducer<PanelComponent> | PanelComponent[]) {\n if (Array.isArray(panels)) {\n this.editViewSidePanels = [...this.editViewSidePanels, ...panels];\n } else if (typeof panels === 'function') {\n this.editViewSidePanels = panels(this.editViewSidePanels);\n } else {\n throw new Error(\n `Expected the \\`panels\\` passed to \\`addEditViewSidePanel\\` to be an array or a function, but received ${getPrintableType(\n panels\n )}`\n );\n }\n }\n\n addDocumentAction(actions: DescriptionReducer<DocumentActionComponent>): void;\n addDocumentAction(actions: DocumentActionComponent[]): void;\n addDocumentAction(\n actions: DescriptionReducer<DocumentActionComponent> | DocumentActionComponent[]\n ) {\n if (Array.isArray(actions)) {\n this.documentActions = [...this.documentActions, ...actions];\n } else if (typeof actions === 'function') {\n this.documentActions = actions(this.documentActions);\n } else {\n throw new Error(\n `Expected the \\`actions\\` passed to \\`addDocumentAction\\` to be an array or a function, but received ${getPrintableType(\n actions\n )}`\n );\n }\n }\n\n addDocumentHeaderAction(actions: DescriptionReducer<HeaderActionComponent>): void;\n addDocumentHeaderAction(actions: HeaderActionComponent[]): void;\n addDocumentHeaderAction(\n actions: DescriptionReducer<HeaderActionComponent> | HeaderActionComponent[]\n ) {\n if (Array.isArray(actions)) {\n this.headerActions = [...this.headerActions, ...actions];\n } else if (typeof actions === 'function') {\n this.headerActions = actions(this.headerActions);\n } else {\n throw new Error(\n `Expected the \\`actions\\` passed to \\`addDocumentHeaderAction\\` to be an array or a function, but received ${getPrintableType(\n actions\n )}`\n );\n }\n }\n\n addBulkAction(actions: DescriptionReducer<BulkActionComponent>): void;\n addBulkAction(actions: BulkActionComponent[]): void;\n addBulkAction(actions: DescriptionReducer<BulkActionComponent> | BulkActionComponent[]) {\n if (Array.isArray(actions)) {\n this.bulkActions = [...this.bulkActions, ...actions];\n } else if (typeof actions === 'function') {\n this.bulkActions = actions(this.bulkActions);\n } else {\n throw new Error(\n `Expected the \\`actions\\` passed to \\`addBulkAction\\` to be an array or a function, but received ${getPrintableType(\n actions\n )}`\n );\n }\n }\n\n get config() {\n return {\n id: PLUGIN_ID,\n name: 'Content Manager',\n injectionZones: INJECTION_ZONES,\n apis: {\n addBulkAction: this.addBulkAction.bind(this),\n addDocumentAction: this.addDocumentAction.bind(this),\n addDocumentHeaderAction: this.addDocumentHeaderAction.bind(this),\n addEditViewSidePanel: this.addEditViewSidePanel.bind(this),\n addRichTextBlocks: this.addRichTextBlocks.bind(this),\n getBulkActions: () => this.bulkActions,\n getDocumentActions: (position?: DocumentActionPosition) => {\n /**\n * When possible, pre-filter the actions by the components static position property.\n * This avoids rendering the actions in multiple places where they weren't displayed,\n * which wasn't visible but created issues with useEffect for instance.\n * The response should still be filtered by the position, as the static property is new\n * and not mandatory to avoid a breaking change.\n */\n if (position) {\n return this.documentActions.filter((action) => {\n return action.position == undefined || [action.position].flat().includes(position);\n });\n }\n\n return this.documentActions;\n },\n getEditViewSidePanels: () => this.editViewSidePanels,\n getHeaderActions: () => this.headerActions,\n getRichTextBlocks: () => ({ ...this.richTextBlocksStore }),\n },\n } satisfies PluginConfig;\n }\n}\n\n/* -------------------------------------------------------------------------------------------------\n * getPrintableType\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Gets the human-friendly printable type name for the given value, for instance it will yield\n * `array` instead of `object`, as the native `typeof` operator would do.\n */\nconst getPrintableType = (value: unknown): string => {\n const nativeType = typeof value;\n\n if (nativeType === 'object') {\n if (value === null) return 'null';\n if (Array.isArray(value)) return 'array';\n if (value instanceof Object && value.constructor.name !== 'Object') {\n return value.constructor.name;\n }\n }\n\n return nativeType;\n};\n\nexport { ContentManagerPlugin };\nexport type {\n EditViewContext,\n ListViewContext,\n BulkActionComponent,\n BulkActionComponentProps,\n BulkActionDescription,\n DescriptionComponent,\n DescriptionReducer,\n PanelComponentProps,\n PanelComponent,\n PanelDescription,\n DocumentActionComponent,\n DocumentActionDescription,\n DocumentActionProps,\n HeaderActionComponent,\n HeaderActionDescription,\n HeaderActionProps,\n};\n"],"names":["ContentManagerPlugin","addRichTextBlocks","blocks","result","richTextBlocksStore","Error","getPrintableType","addEditViewSidePanel","panels","Array","isArray","editViewSidePanels","addDocumentAction","actions","documentActions","addDocumentHeaderAction","headerActions","addBulkAction","bulkActions","config","id","PLUGIN_ID","name","injectionZones","INJECTION_ZONES","apis","bind","getBulkActions","getDocumentActions","position","filter","action","undefined","flat","includes","getEditViewSidePanels","getHeaderActions","getRichTextBlocks","defaultBlocksStore","DEFAULT_BULK_ACTIONS","DEFAULT_ACTIONS","DEFAULT_TABLE_ROW_ACTIONS","DEFAULT_HEADER_ACTIONS","ActionsPanel","value","nativeType","Object"],"mappings":";;;;;;;;;;;AAoHA;;AAEkG,qGAElG,MAAMA,oBAAAA,CAAAA;AAqBJC,IAAAA,iBAAAA,CAAkBC,MAAwE,EAAE;QAC1F,IAAI,OAAOA,WAAW,UAAA,EAAY;AAChC,YAAA,MAAMC,MAAAA,GAASD,MAAAA,CAAO,IAAI,CAACE,mBAAmB,CAAA;AAC9C,YAAA,IAAI,OAAOD,MAAAA,KAAW,QAAA,IAAYA,MAAAA,KAAW,IAAA,EAAM;AACjD,gBAAA,MAAM,IAAIE,KAAAA,CACR,CAAC,oGAAoG,EAAEC,iBAAiBH,MAAAA,CAAAA,CA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AAA,GAA6C;AACxC0B,YAAAA,GAAAA,+BAAAA;AACAC,YAAAA,GAAAA,sCAAAA;AACAC,YAAAA,GAAAA;AACJ,SAAA;aACD/B,kBAAAA,GAAuC;AAACgC,YAAAA;AAAa,SAAA;AACrD3B,QAAAA,IAAAA,CAAAA,aAAAA,GAAyC,EAAE;AAE5B,IAAA;AA8HjB;AAEA;;;;;;IASA,MAAMV,mBAAmB,CAACsC,KAAAA,GAAAA;AACxB,IAAA,MAAMC,aAAa,OAAOD,KAAAA;AAE1B,IAAA,IAAIC,eAAe,QAAA,EAAU;QAC3B,IAAID,KAAAA,KAAU,MAAM,OAAO,MAAA;AAC3B,QAAA,IAAInC,KAAAA,CAAMC,OAAO,CAACkC,KAAAA,CAAAA,EAAQ,OAAO,OAAA;AACjC,QAAA,IAAIA,iBAAiBE,MAAAA,IAAUF,KAAAA,CAAM,WAAW,CAACtB,IAAI,KAAK,QAAA,EAAU;YAClE,OAAOsB,KAAAA,CAAM,WAAW,CAACtB,IAAI;AAC/B,QAAA;AACF,IAAA;IAEA,OAAOuB,UAAAA;AACT,CAAA;;;;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { INJECTION_ZONES } from './components/InjectionZone.mjs';
|
|
2
2
|
import { PLUGIN_ID } from './constants/plugin.mjs';
|
|
3
3
|
import { DEFAULT_ACTIONS } from './pages/EditView/components/DocumentActions.mjs';
|
|
4
|
+
import { defaultBlocksStore } from './pages/EditView/components/FormInputs/BlocksInput/DefaultBlocksStore.mjs';
|
|
4
5
|
import { DEFAULT_HEADER_ACTIONS } from './pages/EditView/components/Header.mjs';
|
|
5
6
|
import { ActionsPanel } from './pages/EditView/components/Panels.mjs';
|
|
6
7
|
import { DEFAULT_BULK_ACTIONS } from './pages/ListView/components/BulkActions/Actions.mjs';
|
|
@@ -9,6 +10,22 @@ import { DEFAULT_TABLE_ROW_ACTIONS } from './pages/ListView/components/TableActi
|
|
|
9
10
|
/* -------------------------------------------------------------------------------------------------
|
|
10
11
|
* ContentManager plugin
|
|
11
12
|
* -----------------------------------------------------------------------------------------------*/ class ContentManagerPlugin {
|
|
13
|
+
addRichTextBlocks(blocks) {
|
|
14
|
+
if (typeof blocks === 'function') {
|
|
15
|
+
const result = blocks(this.richTextBlocksStore);
|
|
16
|
+
if (typeof result !== 'object' || result === null) {
|
|
17
|
+
throw new Error(`Expected the \`blocks\` passed to \`addRichTextBlocks\` to be an object or a function, but received ${getPrintableType(result)}`);
|
|
18
|
+
}
|
|
19
|
+
this.richTextBlocksStore = result;
|
|
20
|
+
} else if (typeof blocks === 'object') {
|
|
21
|
+
this.richTextBlocksStore = {
|
|
22
|
+
...this.richTextBlocksStore,
|
|
23
|
+
...blocks
|
|
24
|
+
};
|
|
25
|
+
} else {
|
|
26
|
+
throw new Error(`Expected the \`blocks\` passed to \`addRichTextBlocks\` to be an object or a function, but received ${getPrintableType(blocks)}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
12
29
|
addEditViewSidePanel(panels) {
|
|
13
30
|
if (Array.isArray(panels)) {
|
|
14
31
|
this.editViewSidePanels = [
|
|
@@ -67,6 +84,7 @@ import { DEFAULT_TABLE_ROW_ACTIONS } from './pages/ListView/components/TableActi
|
|
|
67
84
|
addDocumentAction: this.addDocumentAction.bind(this),
|
|
68
85
|
addDocumentHeaderAction: this.addDocumentHeaderAction.bind(this),
|
|
69
86
|
addEditViewSidePanel: this.addEditViewSidePanel.bind(this),
|
|
87
|
+
addRichTextBlocks: this.addRichTextBlocks.bind(this),
|
|
70
88
|
getBulkActions: ()=>this.bulkActions,
|
|
71
89
|
getDocumentActions: (position)=>{
|
|
72
90
|
/**
|
|
@@ -85,7 +103,10 @@ import { DEFAULT_TABLE_ROW_ACTIONS } from './pages/ListView/components/TableActi
|
|
|
85
103
|
return this.documentActions;
|
|
86
104
|
},
|
|
87
105
|
getEditViewSidePanels: ()=>this.editViewSidePanels,
|
|
88
|
-
getHeaderActions: ()=>this.headerActions
|
|
106
|
+
getHeaderActions: ()=>this.headerActions,
|
|
107
|
+
getRichTextBlocks: ()=>({
|
|
108
|
+
...this.richTextBlocksStore
|
|
109
|
+
})
|
|
89
110
|
}
|
|
90
111
|
};
|
|
91
112
|
}
|
|
@@ -95,7 +116,10 @@ import { DEFAULT_TABLE_ROW_ACTIONS } from './pages/ListView/components/TableActi
|
|
|
95
116
|
* the content-manager. The function calls however, need to be called at runtime in the
|
|
96
117
|
* application, so instead we collate them and run them later with the complete list incl.
|
|
97
118
|
* ones already registered & the context of the view.
|
|
98
|
-
*/ this.
|
|
119
|
+
*/ this.richTextBlocksStore = {
|
|
120
|
+
...defaultBlocksStore
|
|
121
|
+
};
|
|
122
|
+
this.bulkActions = [
|
|
99
123
|
...DEFAULT_BULK_ACTIONS
|
|
100
124
|
];
|
|
101
125
|
this.documentActions = [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-manager.mjs","sources":["../../admin/src/content-manager.ts"],"sourcesContent":["/* eslint-disable check-file/filename-naming-convention */\nimport { INJECTION_ZONES } from './components/InjectionZone';\nimport { PLUGIN_ID } from './constants/plugin';\nimport {\n DEFAULT_ACTIONS,\n type DocumentActionPosition,\n type DocumentActionDescription,\n} from './pages/EditView/components/DocumentActions';\nimport {\n DEFAULT_HEADER_ACTIONS,\n type HeaderActionDescription,\n} from './pages/EditView/components/Header';\nimport { ActionsPanel, type PanelDescription } from './pages/EditView/components/Panels';\nimport {\n DEFAULT_BULK_ACTIONS,\n type BulkActionDescription,\n} from './pages/ListView/components/BulkActions/Actions';\nimport { DEFAULT_TABLE_ROW_ACTIONS } from './pages/ListView/components/TableActions';\n\nimport type { Document } from './hooks/useDocument';\nimport type { DocumentMetadata } from '../../shared/contracts/collection-types';\nimport type { DescriptionComponent, PluginConfig } from '@strapi/admin/strapi-admin';\n\n/* -------------------------------------------------------------------------------------------------\n * Configuration Types\n * -----------------------------------------------------------------------------------------------*/\n\ntype DescriptionReducer<Config extends object> = (prev: Config[]) => Config[];\n\ninterface EditViewContext {\n /**\n * This will ONLY be null, if the content-type\n * does not have draft & published enabled.\n */\n activeTab: 'draft' | 'published' | null;\n /**\n * Will be either 'single-types' | 'collection-types'\n */\n collectionType: string;\n /**\n * this will be undefined if someone is creating an entry.\n */\n document?: Document;\n /**\n * this will be undefined if someone is creating an entry.\n */\n documentId?: string;\n /**\n * this will be undefined if someone is creating an entry.\n */\n meta?: DocumentMetadata;\n /**\n * The current content-type's model.\n */\n model: string;\n}\n\ninterface ListViewContext {\n /**\n * Will be either 'single-types' | 'collection-types'\n */\n collectionType: string;\n /**\n * The current selected documents in the table\n */\n documents: Document[];\n /**\n * The current content-type's model.\n */\n model: string;\n}\n\ninterface PanelComponentProps extends EditViewContext {}\n\ninterface PanelComponent extends DescriptionComponent<PanelComponentProps, PanelDescription> {\n /**\n * The defaults are added by Strapi only, if you're providing your own component,\n * you do not need to provide this.\n */\n type?: 'actions' | 'releases';\n}\n\ninterface DocumentActionProps extends EditViewContext {}\n\ninterface DocumentActionComponent\n extends DescriptionComponent<DocumentActionProps, DocumentActionDescription> {\n type?:\n | 'clone'\n | 'configure-the-view'\n | 'delete'\n | 'discard'\n | 'edit'\n | 'edit-the-model'\n | 'history'\n | 'publish'\n | 'unpublish'\n | 'update';\n position?: DocumentActionDescription['position'];\n}\n\ninterface HeaderActionProps extends EditViewContext {}\n\ninterface HeaderActionComponent\n extends DescriptionComponent<HeaderActionProps, HeaderActionDescription> {}\n\ninterface BulkActionComponentProps extends ListViewContext {}\n\ninterface BulkActionComponent\n extends DescriptionComponent<BulkActionComponentProps, BulkActionDescription> {\n type?: 'delete' | 'publish' | 'unpublish';\n}\n\n/* -------------------------------------------------------------------------------------------------\n * ContentManager plugin\n * -----------------------------------------------------------------------------------------------*/\n\nclass ContentManagerPlugin {\n /**\n * The following properties are the stored ones provided by any plugins registering with\n * the content-manager. The function calls however, need to be called at runtime in the\n * application, so instead we collate them and run them later with the complete list incl.\n * ones already registered & the context of the view.\n */\n bulkActions: BulkActionComponent[] = [...DEFAULT_BULK_ACTIONS];\n documentActions: DocumentActionComponent[] = [\n ...DEFAULT_ACTIONS,\n ...DEFAULT_TABLE_ROW_ACTIONS,\n ...DEFAULT_HEADER_ACTIONS,\n ];\n editViewSidePanels: PanelComponent[] = [ActionsPanel];\n headerActions: HeaderActionComponent[] = [];\n\n constructor() {}\n\n addEditViewSidePanel(panels: DescriptionReducer<PanelComponent>): void;\n addEditViewSidePanel(panels: PanelComponent[]): void;\n addEditViewSidePanel(panels: DescriptionReducer<PanelComponent> | PanelComponent[]) {\n if (Array.isArray(panels)) {\n this.editViewSidePanels = [...this.editViewSidePanels, ...panels];\n } else if (typeof panels === 'function') {\n this.editViewSidePanels = panels(this.editViewSidePanels);\n } else {\n throw new Error(\n `Expected the \\`panels\\` passed to \\`addEditViewSidePanel\\` to be an array or a function, but received ${getPrintableType(\n panels\n )}`\n );\n }\n }\n\n addDocumentAction(actions: DescriptionReducer<DocumentActionComponent>): void;\n addDocumentAction(actions: DocumentActionComponent[]): void;\n addDocumentAction(\n actions: DescriptionReducer<DocumentActionComponent> | DocumentActionComponent[]\n ) {\n if (Array.isArray(actions)) {\n this.documentActions = [...this.documentActions, ...actions];\n } else if (typeof actions === 'function') {\n this.documentActions = actions(this.documentActions);\n } else {\n throw new Error(\n `Expected the \\`actions\\` passed to \\`addDocumentAction\\` to be an array or a function, but received ${getPrintableType(\n actions\n )}`\n );\n }\n }\n\n addDocumentHeaderAction(actions: DescriptionReducer<HeaderActionComponent>): void;\n addDocumentHeaderAction(actions: HeaderActionComponent[]): void;\n addDocumentHeaderAction(\n actions: DescriptionReducer<HeaderActionComponent> | HeaderActionComponent[]\n ) {\n if (Array.isArray(actions)) {\n this.headerActions = [...this.headerActions, ...actions];\n } else if (typeof actions === 'function') {\n this.headerActions = actions(this.headerActions);\n } else {\n throw new Error(\n `Expected the \\`actions\\` passed to \\`addDocumentHeaderAction\\` to be an array or a function, but received ${getPrintableType(\n actions\n )}`\n );\n }\n }\n\n addBulkAction(actions: DescriptionReducer<BulkActionComponent>): void;\n addBulkAction(actions: BulkActionComponent[]): void;\n addBulkAction(actions: DescriptionReducer<BulkActionComponent> | BulkActionComponent[]) {\n if (Array.isArray(actions)) {\n this.bulkActions = [...this.bulkActions, ...actions];\n } else if (typeof actions === 'function') {\n this.bulkActions = actions(this.bulkActions);\n } else {\n throw new Error(\n `Expected the \\`actions\\` passed to \\`addBulkAction\\` to be an array or a function, but received ${getPrintableType(\n actions\n )}`\n );\n }\n }\n\n get config() {\n return {\n id: PLUGIN_ID,\n name: 'Content Manager',\n injectionZones: INJECTION_ZONES,\n apis: {\n addBulkAction: this.addBulkAction.bind(this),\n addDocumentAction: this.addDocumentAction.bind(this),\n addDocumentHeaderAction: this.addDocumentHeaderAction.bind(this),\n addEditViewSidePanel: this.addEditViewSidePanel.bind(this),\n getBulkActions: () => this.bulkActions,\n getDocumentActions: (position?: DocumentActionPosition) => {\n /**\n * When possible, pre-filter the actions by the components static position property.\n * This avoids rendering the actions in multiple places where they weren't displayed,\n * which wasn't visible but created issues with useEffect for instance.\n * The response should still be filtered by the position, as the static property is new\n * and not mandatory to avoid a breaking change.\n */\n if (position) {\n return this.documentActions.filter((action) => {\n return action.position == undefined || [action.position].flat().includes(position);\n });\n }\n\n return this.documentActions;\n },\n getEditViewSidePanels: () => this.editViewSidePanels,\n getHeaderActions: () => this.headerActions,\n },\n } satisfies PluginConfig;\n }\n}\n\n/* -------------------------------------------------------------------------------------------------\n * getPrintableType\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Gets the human-friendly printable type name for the given value, for instance it will yield\n * `array` instead of `object`, as the native `typeof` operator would do.\n */\nconst getPrintableType = (value: unknown): string => {\n const nativeType = typeof value;\n\n if (nativeType === 'object') {\n if (value === null) return 'null';\n if (Array.isArray(value)) return 'array';\n if (value instanceof Object && value.constructor.name !== 'Object') {\n return value.constructor.name;\n }\n }\n\n return nativeType;\n};\n\nexport { ContentManagerPlugin };\nexport type {\n EditViewContext,\n ListViewContext,\n BulkActionComponent,\n BulkActionComponentProps,\n BulkActionDescription,\n DescriptionComponent,\n DescriptionReducer,\n PanelComponentProps,\n PanelComponent,\n PanelDescription,\n DocumentActionComponent,\n DocumentActionDescription,\n DocumentActionProps,\n HeaderActionComponent,\n HeaderActionDescription,\n HeaderActionProps,\n};\n"],"names":["ContentManagerPlugin","addEditViewSidePanel","panels","Array","isArray","editViewSidePanels","Error","getPrintableType","addDocumentAction","actions","documentActions","addDocumentHeaderAction","headerActions","addBulkAction","bulkActions","config","id","PLUGIN_ID","name","injectionZones","INJECTION_ZONES","apis","bind","getBulkActions","getDocumentActions","position","filter","action","undefined","flat","includes","getEditViewSidePanels","getHeaderActions","DEFAULT_BULK_ACTIONS","DEFAULT_ACTIONS","DEFAULT_TABLE_ROW_ACTIONS","DEFAULT_HEADER_ACTIONS","ActionsPanel","value","nativeType","Object"],"mappings":";;;;;;;;AAgHA;;AAEkG,qGAElG,MAAMA,oBAAAA,CAAAA;AAoBJC,IAAAA,oBAAAA,CAAqBC,MAA6D,EAAE;QAClF,IAAIC,KAAAA,CAAMC,OAAO,CAACF,MAAAA,CAAAA,EAAS;YACzB,IAAI,CAACG,kBAAkB,GAAG;AAAI,gBAAA,GAAA,IAAI,CAACA,kBAAkB;AAAKH,gBAAAA,GAAAA;AAAO,aAAA;QACnE,CAAA,MAAO,IAAI,OAAOA,MAAAA,KAAW,UAAA,EAAY;AACvC,YAAA,IAAI,CAACG,kBAAkB,GAAGH,MAAAA,CAAO,IAAI,CAACG,kBAAkB,CAAA;QAC1D,CAAA,MAAO;AACL,YAAA,MAAM,IAAIC,KAAAA,CACR,CAAC,sGAAsG,EAAEC,iBACvGL,MAAAA,CAAAA,CAAAA,CACC,CAAA;AAEP,QAAA;AACF,IAAA;AAIAM,IAAAA,iBAAAA,CACEC,OAAgF,EAChF;QACA,IAAIN,KAAAA,CAAMC,OAAO,CAACK,OAAAA,CAAAA,EAAU;YAC1B,IAAI,CAACC,eAAe,GAAG;AA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;aAC9DvB,eAAAA,GAA6C;AACxCwB,YAAAA,GAAAA,eAAAA;AACAC,YAAAA,GAAAA,yBAAAA;AACAC,YAAAA,GAAAA;AACJ,SAAA;aACD/B,kBAAAA,GAAuC;AAACgC,YAAAA;AAAa,SAAA;AACrDzB,QAAAA,IAAAA,CAAAA,aAAAA,GAAyC,EAAE;AAE5B,IAAA;AAsGjB;AAEA;;;;;;IASA,MAAML,mBAAmB,CAAC+B,KAAAA,GAAAA;AACxB,IAAA,MAAMC,aAAa,OAAOD,KAAAA;AAE1B,IAAA,IAAIC,eAAe,QAAA,EAAU;QAC3B,IAAID,KAAAA,KAAU,MAAM,OAAO,MAAA;AAC3B,QAAA,IAAInC,KAAAA,CAAMC,OAAO,CAACkC,KAAAA,CAAAA,EAAQ,OAAO,OAAA;AACjC,QAAA,IAAIA,iBAAiBE,MAAAA,IAAUF,KAAAA,CAAM,WAAW,CAACpB,IAAI,KAAK,QAAA,EAAU;YAClE,OAAOoB,KAAAA,CAAM,WAAW,CAACpB,IAAI;AAC/B,QAAA;AACF,IAAA;IAEA,OAAOqB,UAAAA;AACT,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"content-manager.mjs","sources":["../../admin/src/content-manager.ts"],"sourcesContent":["/* eslint-disable check-file/filename-naming-convention */\n\nimport { INJECTION_ZONES } from './components/InjectionZone';\nimport { PLUGIN_ID } from './constants/plugin';\nimport {\n DEFAULT_ACTIONS,\n type DocumentActionPosition,\n type DocumentActionDescription,\n} from './pages/EditView/components/DocumentActions';\nimport { RichTextBlocksStore } from './pages/EditView/components/FormInputs/BlocksInput/BlocksEditor';\nimport { defaultBlocksStore } from './pages/EditView/components/FormInputs/BlocksInput/DefaultBlocksStore';\nimport {\n DEFAULT_HEADER_ACTIONS,\n type HeaderActionDescription,\n} from './pages/EditView/components/Header';\nimport { ActionsPanel, type PanelDescription } from './pages/EditView/components/Panels';\nimport {\n DEFAULT_BULK_ACTIONS,\n type BulkActionDescription,\n} from './pages/ListView/components/BulkActions/Actions';\nimport { DEFAULT_TABLE_ROW_ACTIONS } from './pages/ListView/components/TableActions';\n\nimport type { Document } from './hooks/useDocument';\nimport type { DocumentMetadata } from '../../shared/contracts/collection-types';\nimport type { DescriptionComponent, PluginConfig } from '@strapi/admin/strapi-admin';\n\n/* -------------------------------------------------------------------------------------------------\n * Configuration Types\n * -----------------------------------------------------------------------------------------------*/\n\ntype DescriptionReducer<Config extends object> = (prev: Config[]) => Config[];\ntype DescriptionObjReducer<Config extends object> = (prev: Config) => Config;\n\ninterface EditViewContext {\n /**\n * This will ONLY be null, if the content-type\n * does not have draft & published enabled.\n */\n activeTab: 'draft' | 'published' | null;\n /**\n * Will be either 'single-types' | 'collection-types'\n */\n collectionType: string;\n /**\n * this will be undefined if someone is creating an entry.\n */\n document?: Document;\n /**\n * this will be undefined if someone is creating an entry.\n */\n documentId?: string;\n /**\n * this will be undefined if someone is creating an entry.\n */\n meta?: DocumentMetadata;\n /**\n * The current content-type's model.\n */\n model: string;\n}\n\ninterface ListViewContext {\n /**\n * Will be either 'single-types' | 'collection-types'\n */\n collectionType: string;\n /**\n * The current selected documents in the table\n */\n documents: Document[];\n /**\n * The current content-type's model.\n */\n model: string;\n}\n\ninterface PanelComponentProps extends EditViewContext {}\n\ninterface PanelComponent extends DescriptionComponent<PanelComponentProps, PanelDescription> {\n /**\n * The defaults are added by Strapi only, if you're providing your own component,\n * you do not need to provide this.\n */\n type?: 'actions' | 'releases';\n}\n\ninterface DocumentActionProps extends EditViewContext {}\n\ninterface DocumentActionComponent\n extends DescriptionComponent<DocumentActionProps, DocumentActionDescription> {\n type?:\n | 'clone'\n | 'configure-the-view'\n | 'delete'\n | 'discard'\n | 'edit'\n | 'edit-the-model'\n | 'history'\n | 'publish'\n | 'unpublish'\n | 'update';\n position?: DocumentActionDescription['position'];\n}\n\ninterface HeaderActionProps extends EditViewContext {}\n\ninterface HeaderActionComponent\n extends DescriptionComponent<HeaderActionProps, HeaderActionDescription> {}\n\ninterface BulkActionComponentProps extends ListViewContext {}\n\ninterface BulkActionComponent\n extends DescriptionComponent<BulkActionComponentProps, BulkActionDescription> {\n type?: 'delete' | 'publish' | 'unpublish';\n}\n\n/* -------------------------------------------------------------------------------------------------\n * ContentManager plugin\n * -----------------------------------------------------------------------------------------------*/\n\nclass ContentManagerPlugin {\n /**\n * The following properties are the stored ones provided by any plugins registering with\n * the content-manager. The function calls however, need to be called at runtime in the\n * application, so instead we collate them and run them later with the complete list incl.\n * ones already registered & the context of the view.\n */\n richTextBlocksStore: RichTextBlocksStore = { ...defaultBlocksStore };\n bulkActions: BulkActionComponent[] = [...DEFAULT_BULK_ACTIONS];\n documentActions: DocumentActionComponent[] = [\n ...DEFAULT_ACTIONS,\n ...DEFAULT_TABLE_ROW_ACTIONS,\n ...DEFAULT_HEADER_ACTIONS,\n ];\n editViewSidePanels: PanelComponent[] = [ActionsPanel];\n headerActions: HeaderActionComponent[] = [];\n\n constructor() {}\n\n addRichTextBlocks(blocks: RichTextBlocksStore): void;\n addRichTextBlocks(blocks: DescriptionObjReducer<RichTextBlocksStore>): void;\n addRichTextBlocks(blocks: RichTextBlocksStore | DescriptionObjReducer<RichTextBlocksStore>) {\n if (typeof blocks === 'function') {\n const result = blocks(this.richTextBlocksStore);\n if (typeof result !== 'object' || result === null) {\n throw new Error(\n `Expected the \\`blocks\\` passed to \\`addRichTextBlocks\\` to be an object or a function, but received ${getPrintableType(result)}`\n );\n }\n this.richTextBlocksStore = result;\n } else if (typeof blocks === 'object') {\n this.richTextBlocksStore = { ...this.richTextBlocksStore, ...blocks };\n } else {\n throw new Error(\n `Expected the \\`blocks\\` passed to \\`addRichTextBlocks\\` to be an object or a function, but received ${getPrintableType(\n blocks\n )}`\n );\n }\n }\n\n addEditViewSidePanel(panels: DescriptionReducer<PanelComponent>): void;\n addEditViewSidePanel(panels: PanelComponent[]): void;\n addEditViewSidePanel(panels: DescriptionReducer<PanelComponent> | PanelComponent[]) {\n if (Array.isArray(panels)) {\n this.editViewSidePanels = [...this.editViewSidePanels, ...panels];\n } else if (typeof panels === 'function') {\n this.editViewSidePanels = panels(this.editViewSidePanels);\n } else {\n throw new Error(\n `Expected the \\`panels\\` passed to \\`addEditViewSidePanel\\` to be an array or a function, but received ${getPrintableType(\n panels\n )}`\n );\n }\n }\n\n addDocumentAction(actions: DescriptionReducer<DocumentActionComponent>): void;\n addDocumentAction(actions: DocumentActionComponent[]): void;\n addDocumentAction(\n actions: DescriptionReducer<DocumentActionComponent> | DocumentActionComponent[]\n ) {\n if (Array.isArray(actions)) {\n this.documentActions = [...this.documentActions, ...actions];\n } else if (typeof actions === 'function') {\n this.documentActions = actions(this.documentActions);\n } else {\n throw new Error(\n `Expected the \\`actions\\` passed to \\`addDocumentAction\\` to be an array or a function, but received ${getPrintableType(\n actions\n )}`\n );\n }\n }\n\n addDocumentHeaderAction(actions: DescriptionReducer<HeaderActionComponent>): void;\n addDocumentHeaderAction(actions: HeaderActionComponent[]): void;\n addDocumentHeaderAction(\n actions: DescriptionReducer<HeaderActionComponent> | HeaderActionComponent[]\n ) {\n if (Array.isArray(actions)) {\n this.headerActions = [...this.headerActions, ...actions];\n } else if (typeof actions === 'function') {\n this.headerActions = actions(this.headerActions);\n } else {\n throw new Error(\n `Expected the \\`actions\\` passed to \\`addDocumentHeaderAction\\` to be an array or a function, but received ${getPrintableType(\n actions\n )}`\n );\n }\n }\n\n addBulkAction(actions: DescriptionReducer<BulkActionComponent>): void;\n addBulkAction(actions: BulkActionComponent[]): void;\n addBulkAction(actions: DescriptionReducer<BulkActionComponent> | BulkActionComponent[]) {\n if (Array.isArray(actions)) {\n this.bulkActions = [...this.bulkActions, ...actions];\n } else if (typeof actions === 'function') {\n this.bulkActions = actions(this.bulkActions);\n } else {\n throw new Error(\n `Expected the \\`actions\\` passed to \\`addBulkAction\\` to be an array or a function, but received ${getPrintableType(\n actions\n )}`\n );\n }\n }\n\n get config() {\n return {\n id: PLUGIN_ID,\n name: 'Content Manager',\n injectionZones: INJECTION_ZONES,\n apis: {\n addBulkAction: this.addBulkAction.bind(this),\n addDocumentAction: this.addDocumentAction.bind(this),\n addDocumentHeaderAction: this.addDocumentHeaderAction.bind(this),\n addEditViewSidePanel: this.addEditViewSidePanel.bind(this),\n addRichTextBlocks: this.addRichTextBlocks.bind(this),\n getBulkActions: () => this.bulkActions,\n getDocumentActions: (position?: DocumentActionPosition) => {\n /**\n * When possible, pre-filter the actions by the components static position property.\n * This avoids rendering the actions in multiple places where they weren't displayed,\n * which wasn't visible but created issues with useEffect for instance.\n * The response should still be filtered by the position, as the static property is new\n * and not mandatory to avoid a breaking change.\n */\n if (position) {\n return this.documentActions.filter((action) => {\n return action.position == undefined || [action.position].flat().includes(position);\n });\n }\n\n return this.documentActions;\n },\n getEditViewSidePanels: () => this.editViewSidePanels,\n getHeaderActions: () => this.headerActions,\n getRichTextBlocks: () => ({ ...this.richTextBlocksStore }),\n },\n } satisfies PluginConfig;\n }\n}\n\n/* -------------------------------------------------------------------------------------------------\n * getPrintableType\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Gets the human-friendly printable type name for the given value, for instance it will yield\n * `array` instead of `object`, as the native `typeof` operator would do.\n */\nconst getPrintableType = (value: unknown): string => {\n const nativeType = typeof value;\n\n if (nativeType === 'object') {\n if (value === null) return 'null';\n if (Array.isArray(value)) return 'array';\n if (value instanceof Object && value.constructor.name !== 'Object') {\n return value.constructor.name;\n }\n }\n\n return nativeType;\n};\n\nexport { ContentManagerPlugin };\nexport type {\n EditViewContext,\n ListViewContext,\n BulkActionComponent,\n BulkActionComponentProps,\n BulkActionDescription,\n DescriptionComponent,\n DescriptionReducer,\n PanelComponentProps,\n PanelComponent,\n PanelDescription,\n DocumentActionComponent,\n DocumentActionDescription,\n DocumentActionProps,\n HeaderActionComponent,\n HeaderActionDescription,\n HeaderActionProps,\n};\n"],"names":["ContentManagerPlugin","addRichTextBlocks","blocks","result","richTextBlocksStore","Error","getPrintableType","addEditViewSidePanel","panels","Array","isArray","editViewSidePanels","addDocumentAction","actions","documentActions","addDocumentHeaderAction","headerActions","addBulkAction","bulkActions","config","id","PLUGIN_ID","name","injectionZones","INJECTION_ZONES","apis","bind","getBulkActions","getDocumentActions","position","filter","action","undefined","flat","includes","getEditViewSidePanels","getHeaderActions","getRichTextBlocks","defaultBlocksStore","DEFAULT_BULK_ACTIONS","DEFAULT_ACTIONS","DEFAULT_TABLE_ROW_ACTIONS","DEFAULT_HEADER_ACTIONS","ActionsPanel","value","nativeType","Object"],"mappings":";;;;;;;;;AAoHA;;AAEkG,qGAElG,MAAMA,oBAAAA,CAAAA;AAqBJC,IAAAA,iBAAAA,CAAkBC,MAAwE,EAAE;QAC1F,IAAI,OAAOA,WAAW,UAAA,EAAY;AAChC,YAAA,MAAMC,MAAAA,GAASD,MAAAA,CAAO,IAAI,CAACE,mBAAmB,CAAA;AAC9C,YAAA,IAAI,OAAOD,MAAAA,KAAW,QAAA,IAAYA,MAAAA,KAAW,IAAA,EAAM;AACjD,gBAAA,MAAM,IAAIE,KAAAA,CACR,CAAC,oGAAoG,EAAEC,iBAAiBH,MAAAA,CAAAA,CAAAA,CAAS,CAAA;AAErI,YAAA;YACA,IAAI,CAACC,mBAAmB,GAAGD,MAAAA;QAC7B,CAAA,MAAO,IAAI,OAAOD,MAAAA,KAAW,QAAA,EAAU;YACrC,IAAI,CAACE,mBAAmB,GAAG;gBAAE,GAAG,IAAI,CAACA,mBAAmB;AAAE,gBAAA,GAAGF;AAAO,aAAA;QACtE,CAAA,MAAO;AACL,YAAA,MAAM,IAAIG,KAAAA,CACR,CAAC,oGAAoG,EAAEC,iBACrGJ,MAAAA,CAAAA,CAAAA,CACC,CAAA;AAEP,QAAA;AACF,IAAA;AAIAK,IAAAA,oBAAAA,CAAqBC,MAA6D,EAAE;QAClF,IAAIC,KAAAA,CAAMC,OAAO,CAACF,MAAAA,CAAAA,EAAS;YACzB,IAAI,CAACG,kBAAkB,GAAG;AAAI,gBAAA,GAAA,IAAI,CAACA,kBAA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AAW,CAACtB,IAAI,KAAK,QAAA,EAAU;YAClE,OAAOsB,KAAAA,CAAM,WAAW,CAACtB,IAAI;AAC/B,QAAA;AACF,IAAA;IAEA,OAAOuB,UAAAA;AACT,CAAA;;;;"}
|
|
@@ -104,7 +104,10 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
|
104
104
|
...new Set(componentUids)
|
|
105
105
|
];
|
|
106
106
|
const componentsByKey = uniqueComponentUids.reduce((acc, uid)=>{
|
|
107
|
-
|
|
107
|
+
const component = allComponents[uid];
|
|
108
|
+
if (component) {
|
|
109
|
+
acc[uid] = component;
|
|
110
|
+
}
|
|
108
111
|
return acc;
|
|
109
112
|
}, {});
|
|
110
113
|
return componentsByKey;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useContentTypeSchema.js","sources":["../../../admin/src/hooks/useContentTypeSchema.ts"],"sourcesContent":["import * as React from 'react';\n\nimport { useNotification, useAPIErrorHandler } from '@strapi/admin/strapi-admin';\n\nimport { useGetInitialDataQuery } from '../services/init';\n\nimport type { Component } from '../../../shared/contracts/components';\nimport type { ContentType } from '../../../shared/contracts/content-types';\nimport type { Schema } from '@strapi/types';\n\n/* -------------------------------------------------------------------------------------------------\n * useContentTypeSchema\n * -----------------------------------------------------------------------------------------------*/\ntype ComponentsDictionary = Record<string, Component>;\n\n/**\n * @internal\n * @description Given a model UID, return the schema and the schemas\n * of the associated components within said model's schema. A wrapper\n * implementation around the `useGetInitialDataQuery` with a unique\n * `selectFromResult` function to memoize the calculation.\n *\n * If no model is provided, the hook will return all the schemas.\n */\nconst useContentTypeSchema = (model?: string) => {\n const { toggleNotification } = useNotification();\n const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();\n\n const { data, error, isLoading, isFetching } = useGetInitialDataQuery(undefined);\n\n const { components, contentType, contentTypes } = React.useMemo(() => {\n const contentType = data?.contentTypes.find((ct) => ct.uid === model);\n\n const componentsByKey = data?.components.reduce<ComponentsDictionary>((acc, component) => {\n acc[component.uid] = component;\n\n return acc;\n }, {});\n\n const components = extractContentTypeComponents(contentType?.attributes, componentsByKey);\n\n return {\n components: Object.keys(components).length === 0 ? undefined : components,\n contentType,\n contentTypes: data?.contentTypes ?? [],\n };\n }, [model, data]);\n\n React.useEffect(() => {\n if (error) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(error),\n });\n }\n }, [toggleNotification, error, formatAPIError]);\n\n return {\n // This must be memoized to avoid inifiinite re-renders where the empty object is different everytime.\n components: React.useMemo(() => components ?? {}, [components]),\n schema: contentType,\n schemas: contentTypes,\n isLoading: isLoading || isFetching,\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * extractContentTypeComponents\n * -----------------------------------------------------------------------------------------------*/\n/**\n * @internal\n * @description Extracts the components used in a content type's attributes recursively.\n */\nconst extractContentTypeComponents = (\n attributes: ContentType['attributes'] = {},\n allComponents: ComponentsDictionary = {}\n): ComponentsDictionary => {\n const getComponents = (attributes: Schema.Attribute.AnyAttribute[]) => {\n return attributes.reduce<string[]>((acc, attribute) => {\n /**\n * If the attribute is a component or dynamiczone, we need to recursively\n * extract the component UIDs from its attributes.\n */\n if (attribute.type === 'component') {\n const componentAttributes = Object.values(\n allComponents[attribute.component]?.attributes ?? {}\n );\n\n acc.push(attribute.component, ...getComponents(componentAttributes));\n } else if (attribute.type === 'dynamiczone') {\n acc.push(\n ...attribute.components,\n /**\n * Dynamic zones have an array of components, so we flatMap over them\n * performing the same search as above.\n */\n ...attribute.components.flatMap((componentUid) => {\n const componentAttributes = Object.values(\n allComponents[componentUid]?.attributes ?? {}\n );\n\n return getComponents(componentAttributes);\n })\n );\n }\n\n return acc;\n }, []);\n };\n\n const componentUids = getComponents(Object.values(attributes));\n\n const uniqueComponentUids = [...new Set(componentUids)];\n\n const componentsByKey = uniqueComponentUids.reduce<ComponentsDictionary>((acc, uid) => {\n
|
|
1
|
+
{"version":3,"file":"useContentTypeSchema.js","sources":["../../../admin/src/hooks/useContentTypeSchema.ts"],"sourcesContent":["import * as React from 'react';\n\nimport { useNotification, useAPIErrorHandler } from '@strapi/admin/strapi-admin';\n\nimport { useGetInitialDataQuery } from '../services/init';\n\nimport type { Component } from '../../../shared/contracts/components';\nimport type { ContentType } from '../../../shared/contracts/content-types';\nimport type { Schema } from '@strapi/types';\n\n/* -------------------------------------------------------------------------------------------------\n * useContentTypeSchema\n * -----------------------------------------------------------------------------------------------*/\ntype ComponentsDictionary = Record<string, Component>;\n\n/**\n * @internal\n * @description Given a model UID, return the schema and the schemas\n * of the associated components within said model's schema. A wrapper\n * implementation around the `useGetInitialDataQuery` with a unique\n * `selectFromResult` function to memoize the calculation.\n *\n * If no model is provided, the hook will return all the schemas.\n */\nconst useContentTypeSchema = (model?: string) => {\n const { toggleNotification } = useNotification();\n const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();\n\n const { data, error, isLoading, isFetching } = useGetInitialDataQuery(undefined);\n\n const { components, contentType, contentTypes } = React.useMemo(() => {\n const contentType = data?.contentTypes.find((ct) => ct.uid === model);\n\n const componentsByKey = data?.components.reduce<ComponentsDictionary>((acc, component) => {\n acc[component.uid] = component;\n\n return acc;\n }, {});\n\n const components = extractContentTypeComponents(contentType?.attributes, componentsByKey);\n\n return {\n components: Object.keys(components).length === 0 ? undefined : components,\n contentType,\n contentTypes: data?.contentTypes ?? [],\n };\n }, [model, data]);\n\n React.useEffect(() => {\n if (error) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(error),\n });\n }\n }, [toggleNotification, error, formatAPIError]);\n\n return {\n // This must be memoized to avoid inifiinite re-renders where the empty object is different everytime.\n components: React.useMemo(() => components ?? {}, [components]),\n schema: contentType,\n schemas: contentTypes,\n isLoading: isLoading || isFetching,\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * extractContentTypeComponents\n * -----------------------------------------------------------------------------------------------*/\n/**\n * @internal\n * @description Extracts the components used in a content type's attributes recursively.\n */\nconst extractContentTypeComponents = (\n attributes: ContentType['attributes'] = {},\n allComponents: ComponentsDictionary = {}\n): ComponentsDictionary => {\n const getComponents = (attributes: Schema.Attribute.AnyAttribute[]) => {\n return attributes.reduce<string[]>((acc, attribute) => {\n /**\n * If the attribute is a component or dynamiczone, we need to recursively\n * extract the component UIDs from its attributes.\n */\n if (attribute.type === 'component') {\n const componentAttributes = Object.values(\n allComponents[attribute.component]?.attributes ?? {}\n );\n\n acc.push(attribute.component, ...getComponents(componentAttributes));\n } else if (attribute.type === 'dynamiczone') {\n acc.push(\n ...attribute.components,\n /**\n * Dynamic zones have an array of components, so we flatMap over them\n * performing the same search as above.\n */\n ...attribute.components.flatMap((componentUid) => {\n const componentAttributes = Object.values(\n allComponents[componentUid]?.attributes ?? {}\n );\n\n return getComponents(componentAttributes);\n })\n );\n }\n\n return acc;\n }, []);\n };\n\n const componentUids = getComponents(Object.values(attributes));\n\n const uniqueComponentUids = [...new Set(componentUids)];\n\n const componentsByKey = uniqueComponentUids.reduce<ComponentsDictionary>((acc, uid) => {\n const component = allComponents[uid];\n if (component) {\n acc[uid] = component;\n }\n\n return acc;\n }, {});\n\n return componentsByKey;\n};\n\nexport { useContentTypeSchema, extractContentTypeComponents };\nexport type { ComponentsDictionary };\n"],"names":["useContentTypeSchema","model","toggleNotification","useNotification","_unstableFormatAPIError","formatAPIError","useAPIErrorHandler","data","error","isLoading","isFetching","useGetInitialDataQuery","undefined","components","contentType","contentTypes","React","useMemo","find","ct","uid","componentsByKey","reduce","acc","component","extractContentTypeComponents","attributes","Object","keys","length","useEffect","type","message","schema","schemas","allComponents","getComponents","attribute","componentAttributes","values","push","flatMap","componentUid","componentUids","uniqueComponentUids","Set"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAeA;;;;;;;;IASA,MAAMA,uBAAuB,CAACC,KAAAA,GAAAA;IAC5B,MAAM,EAAEC,kBAAkB,EAAE,GAAGC,2BAAAA,EAAAA;AAC/B,IAAA,MAAM,EAAEC,uBAAAA,EAAyBC,cAAc,EAAE,GAAGC,8BAAAA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A,OAAOf,GAAAA;AACT,QAAA,CAAA,EAAG,EAAE,CAAA;AACP,IAAA,CAAA;AAEA,IAAA,MAAMoB,aAAAA,GAAgBP,aAAAA,CAAcT,MAAAA,CAAOY,MAAM,CAACb,UAAAA,CAAAA,CAAAA;AAElD,IAAA,MAAMkB,mBAAAA,GAAsB;AAAI,QAAA,GAAA,IAAIC,GAAAA,CAAIF,aAAAA;AAAe,KAAA;AAEvD,IAAA,MAAMtB,eAAAA,GAAkBuB,mBAAAA,CAAoBtB,MAAM,CAAuB,CAACC,GAAAA,EAAKH,GAAAA,GAAAA;QAC7E,MAAMI,SAAAA,GAAYW,aAAa,CAACf,GAAAA,CAAI;AACpC,QAAA,IAAII,SAAAA,EAAW;YACbD,GAAG,CAACH,IAAI,GAAGI,SAAAA;AACb,QAAA;QAEA,OAAOD,GAAAA;AACT,IAAA,CAAA,EAAG,EAAC,CAAA;IAEJ,OAAOF,eAAAA;AACT;;;;;"}
|
|
@@ -83,7 +83,10 @@ import { useGetInitialDataQuery } from '../services/init.mjs';
|
|
|
83
83
|
...new Set(componentUids)
|
|
84
84
|
];
|
|
85
85
|
const componentsByKey = uniqueComponentUids.reduce((acc, uid)=>{
|
|
86
|
-
|
|
86
|
+
const component = allComponents[uid];
|
|
87
|
+
if (component) {
|
|
88
|
+
acc[uid] = component;
|
|
89
|
+
}
|
|
87
90
|
return acc;
|
|
88
91
|
}, {});
|
|
89
92
|
return componentsByKey;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useContentTypeSchema.mjs","sources":["../../../admin/src/hooks/useContentTypeSchema.ts"],"sourcesContent":["import * as React from 'react';\n\nimport { useNotification, useAPIErrorHandler } from '@strapi/admin/strapi-admin';\n\nimport { useGetInitialDataQuery } from '../services/init';\n\nimport type { Component } from '../../../shared/contracts/components';\nimport type { ContentType } from '../../../shared/contracts/content-types';\nimport type { Schema } from '@strapi/types';\n\n/* -------------------------------------------------------------------------------------------------\n * useContentTypeSchema\n * -----------------------------------------------------------------------------------------------*/\ntype ComponentsDictionary = Record<string, Component>;\n\n/**\n * @internal\n * @description Given a model UID, return the schema and the schemas\n * of the associated components within said model's schema. A wrapper\n * implementation around the `useGetInitialDataQuery` with a unique\n * `selectFromResult` function to memoize the calculation.\n *\n * If no model is provided, the hook will return all the schemas.\n */\nconst useContentTypeSchema = (model?: string) => {\n const { toggleNotification } = useNotification();\n const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();\n\n const { data, error, isLoading, isFetching } = useGetInitialDataQuery(undefined);\n\n const { components, contentType, contentTypes } = React.useMemo(() => {\n const contentType = data?.contentTypes.find((ct) => ct.uid === model);\n\n const componentsByKey = data?.components.reduce<ComponentsDictionary>((acc, component) => {\n acc[component.uid] = component;\n\n return acc;\n }, {});\n\n const components = extractContentTypeComponents(contentType?.attributes, componentsByKey);\n\n return {\n components: Object.keys(components).length === 0 ? undefined : components,\n contentType,\n contentTypes: data?.contentTypes ?? [],\n };\n }, [model, data]);\n\n React.useEffect(() => {\n if (error) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(error),\n });\n }\n }, [toggleNotification, error, formatAPIError]);\n\n return {\n // This must be memoized to avoid inifiinite re-renders where the empty object is different everytime.\n components: React.useMemo(() => components ?? {}, [components]),\n schema: contentType,\n schemas: contentTypes,\n isLoading: isLoading || isFetching,\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * extractContentTypeComponents\n * -----------------------------------------------------------------------------------------------*/\n/**\n * @internal\n * @description Extracts the components used in a content type's attributes recursively.\n */\nconst extractContentTypeComponents = (\n attributes: ContentType['attributes'] = {},\n allComponents: ComponentsDictionary = {}\n): ComponentsDictionary => {\n const getComponents = (attributes: Schema.Attribute.AnyAttribute[]) => {\n return attributes.reduce<string[]>((acc, attribute) => {\n /**\n * If the attribute is a component or dynamiczone, we need to recursively\n * extract the component UIDs from its attributes.\n */\n if (attribute.type === 'component') {\n const componentAttributes = Object.values(\n allComponents[attribute.component]?.attributes ?? {}\n );\n\n acc.push(attribute.component, ...getComponents(componentAttributes));\n } else if (attribute.type === 'dynamiczone') {\n acc.push(\n ...attribute.components,\n /**\n * Dynamic zones have an array of components, so we flatMap over them\n * performing the same search as above.\n */\n ...attribute.components.flatMap((componentUid) => {\n const componentAttributes = Object.values(\n allComponents[componentUid]?.attributes ?? {}\n );\n\n return getComponents(componentAttributes);\n })\n );\n }\n\n return acc;\n }, []);\n };\n\n const componentUids = getComponents(Object.values(attributes));\n\n const uniqueComponentUids = [...new Set(componentUids)];\n\n const componentsByKey = uniqueComponentUids.reduce<ComponentsDictionary>((acc, uid) => {\n
|
|
1
|
+
{"version":3,"file":"useContentTypeSchema.mjs","sources":["../../../admin/src/hooks/useContentTypeSchema.ts"],"sourcesContent":["import * as React from 'react';\n\nimport { useNotification, useAPIErrorHandler } from '@strapi/admin/strapi-admin';\n\nimport { useGetInitialDataQuery } from '../services/init';\n\nimport type { Component } from '../../../shared/contracts/components';\nimport type { ContentType } from '../../../shared/contracts/content-types';\nimport type { Schema } from '@strapi/types';\n\n/* -------------------------------------------------------------------------------------------------\n * useContentTypeSchema\n * -----------------------------------------------------------------------------------------------*/\ntype ComponentsDictionary = Record<string, Component>;\n\n/**\n * @internal\n * @description Given a model UID, return the schema and the schemas\n * of the associated components within said model's schema. A wrapper\n * implementation around the `useGetInitialDataQuery` with a unique\n * `selectFromResult` function to memoize the calculation.\n *\n * If no model is provided, the hook will return all the schemas.\n */\nconst useContentTypeSchema = (model?: string) => {\n const { toggleNotification } = useNotification();\n const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();\n\n const { data, error, isLoading, isFetching } = useGetInitialDataQuery(undefined);\n\n const { components, contentType, contentTypes } = React.useMemo(() => {\n const contentType = data?.contentTypes.find((ct) => ct.uid === model);\n\n const componentsByKey = data?.components.reduce<ComponentsDictionary>((acc, component) => {\n acc[component.uid] = component;\n\n return acc;\n }, {});\n\n const components = extractContentTypeComponents(contentType?.attributes, componentsByKey);\n\n return {\n components: Object.keys(components).length === 0 ? undefined : components,\n contentType,\n contentTypes: data?.contentTypes ?? [],\n };\n }, [model, data]);\n\n React.useEffect(() => {\n if (error) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(error),\n });\n }\n }, [toggleNotification, error, formatAPIError]);\n\n return {\n // This must be memoized to avoid inifiinite re-renders where the empty object is different everytime.\n components: React.useMemo(() => components ?? {}, [components]),\n schema: contentType,\n schemas: contentTypes,\n isLoading: isLoading || isFetching,\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * extractContentTypeComponents\n * -----------------------------------------------------------------------------------------------*/\n/**\n * @internal\n * @description Extracts the components used in a content type's attributes recursively.\n */\nconst extractContentTypeComponents = (\n attributes: ContentType['attributes'] = {},\n allComponents: ComponentsDictionary = {}\n): ComponentsDictionary => {\n const getComponents = (attributes: Schema.Attribute.AnyAttribute[]) => {\n return attributes.reduce<string[]>((acc, attribute) => {\n /**\n * If the attribute is a component or dynamiczone, we need to recursively\n * extract the component UIDs from its attributes.\n */\n if (attribute.type === 'component') {\n const componentAttributes = Object.values(\n allComponents[attribute.component]?.attributes ?? {}\n );\n\n acc.push(attribute.component, ...getComponents(componentAttributes));\n } else if (attribute.type === 'dynamiczone') {\n acc.push(\n ...attribute.components,\n /**\n * Dynamic zones have an array of components, so we flatMap over them\n * performing the same search as above.\n */\n ...attribute.components.flatMap((componentUid) => {\n const componentAttributes = Object.values(\n allComponents[componentUid]?.attributes ?? {}\n );\n\n return getComponents(componentAttributes);\n })\n );\n }\n\n return acc;\n }, []);\n };\n\n const componentUids = getComponents(Object.values(attributes));\n\n const uniqueComponentUids = [...new Set(componentUids)];\n\n const componentsByKey = uniqueComponentUids.reduce<ComponentsDictionary>((acc, uid) => {\n const component = allComponents[uid];\n if (component) {\n acc[uid] = component;\n }\n\n return acc;\n }, {});\n\n return componentsByKey;\n};\n\nexport { useContentTypeSchema, extractContentTypeComponents };\nexport type { ComponentsDictionary };\n"],"names":["useContentTypeSchema","model","toggleNotification","useNotification","_unstableFormatAPIError","formatAPIError","useAPIErrorHandler","data","error","isLoading","isFetching","useGetInitialDataQuery","undefined","components","contentType","contentTypes","React","useMemo","find","ct","uid","componentsByKey","reduce","acc","component","extractContentTypeComponents","attributes","Object","keys","length","useEffect","type","message","schema","schemas","allComponents","getComponents","attribute","componentAttributes","values","push","flatMap","componentUid","componentUids","uniqueComponentUids","Set"],"mappings":";;;;AAeA;;;;;;;;IASA,MAAMA,uBAAuB,CAACC,KAAAA,GAAAA;IAC5B,MAAM,EAAEC,kBAAkB,EAAE,GAAGC,eAAAA,EAAAA;AAC/B,IAAA,MAAM,EAAEC,uBAAAA,EAAyBC,cAAc,EAAE,GAAGC,kBAAAA,EAAAA;IAEpD,MAAM,EAAEC,IAAI,EAAEC,KAAK,EAAEC,SAAS,EAAEC,UAAU,EAAE,GAAGC,sBAAAA,CAAuBC,SAAAA,CAAAA;IAEtE,MAAM,EAAEC,UAAU,EAAEC,WAAW,EAAEC,YAAY,EAAE,GAAGC,KAAAA,CAAMC,OAAO,CAAC,IAAA;QAC9D,MAAMH,WAAAA,GAAcP,MAAMQ,YAAAA,CAAaG,IAAAA,CAAK,CAACC,EAAAA,GAAOA,EAAAA,CAAGC,GAAG,KAAKnB,KAAAA,CAAAA;AAE/D,QAAA,MAAMoB,eAAAA,GAAkBd,IAAAA,EAAMM,UAAAA,CAAWS,MAAAA,CAA6B,CAACC,GAAAA,EAAKC,SAAAA,GAAAA;AAC1ED,YAAAA,GAAG,CAACC,SAAAA,CAAUJ,GAAG,CAAC,GAAGI,SAAAA;YAErB,OAAOD,GAAAA;AACT,QAAA,CAAA,EAAG,EAAC,CAAA;QAEJ,MAAMV,UAAAA,GAAaY,4BAAAA,CAA6BX,WAAAA,EAAaY,UAAAA,EAAYL,eAAAA,CAAAA;QAEzE,OAAO;AACLR,YAAAA,UAAAA,EAAYc,OAAOC,IAAI,CAACf,YAAYgB,MAAM,KAAK,IAAIjB,SAAAA,GAAYC,UAAAA;AAC/DC,YAAAA,WAAAA;YACAC,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AID,SAAAA,CAAUN,IAAI,KAAK,aAAA,EAAe;AAC3CR,gBAAAA,GAAAA,CAAIiB,IAAI,CAAA,GACHH,SAAAA,CAAUxB,UAAU;;;AAItB,cAAA,GACEwB,SAAAA,CAAUxB,UAAU,CAAC4B,OAAO,CAAC,CAACC,YAAAA,GAAAA;oBAC/B,MAAMJ,mBAAAA,GAAsBX,OAAOY,MAAM,CACvCJ,aAAa,CAACO,YAAAA,CAAa,EAAEhB,UAAAA,IAAc,EAAC,CAAA;AAG9C,oBAAA,OAAOU,aAAAA,CAAcE,mBAAAA,CAAAA;AACvB,gBAAA,CAAA,CAAA,CAAA;AAEJ,YAAA;YAEA,OAAOf,GAAAA;AACT,QAAA,CAAA,EAAG,EAAE,CAAA;AACP,IAAA,CAAA;AAEA,IAAA,MAAMoB,aAAAA,GAAgBP,aAAAA,CAAcT,MAAAA,CAAOY,MAAM,CAACb,UAAAA,CAAAA,CAAAA;AAElD,IAAA,MAAMkB,mBAAAA,GAAsB;AAAI,QAAA,GAAA,IAAIC,GAAAA,CAAIF,aAAAA;AAAe,KAAA;AAEvD,IAAA,MAAMtB,eAAAA,GAAkBuB,mBAAAA,CAAoBtB,MAAM,CAAuB,CAACC,GAAAA,EAAKH,GAAAA,GAAAA;QAC7E,MAAMI,SAAAA,GAAYW,aAAa,CAACf,GAAAA,CAAI;AACpC,QAAA,IAAII,SAAAA,EAAW;YACbD,GAAG,CAACH,IAAI,GAAGI,SAAAA;AACb,QAAA;QAEA,OAAOD,GAAAA;AACT,IAAA,CAAA,EAAG,EAAC,CAAA;IAEJ,OAAOF,eAAAA;AACT;;;;"}
|
|
@@ -69,8 +69,10 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
|
69
69
|
const { toggleNotification } = strapiAdmin.useNotification();
|
|
70
70
|
const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler();
|
|
71
71
|
const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema.useContentTypeSchema();
|
|
72
|
-
const { data, isLoading: isLoadingConfigs, error } = contentTypes.useGetContentTypeConfigurationQuery(model);
|
|
73
|
-
const
|
|
72
|
+
const { currentData: data, isLoading: isLoadingConfigs, error } = contentTypes.useGetContentTypeConfigurationQuery(model);
|
|
73
|
+
const isConfigResolvedForModel = data?.contentType?.uid === model;
|
|
74
|
+
const isLoading = isLoadingSchemas || isLoadingConfigs || !error && !isConfigResolvedForModel;
|
|
75
|
+
const stableLayoutsByModelRef = React__namespace.useRef(new Map());
|
|
74
76
|
React__namespace.useEffect(()=>{
|
|
75
77
|
if (error) {
|
|
76
78
|
toggleNotification({
|
|
@@ -83,40 +85,62 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
|
83
85
|
formatAPIError,
|
|
84
86
|
toggleNotification
|
|
85
87
|
]);
|
|
86
|
-
const
|
|
88
|
+
const resolvedLayouts = React__namespace.useMemo(()=>{
|
|
89
|
+
if (!data || isLoading) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
const edit = formatEditLayout(data, {
|
|
93
|
+
schemas,
|
|
94
|
+
schema,
|
|
95
|
+
components
|
|
96
|
+
});
|
|
97
|
+
const list = formatListLayout(data, {
|
|
87
98
|
schemas,
|
|
88
99
|
schema,
|
|
89
100
|
components
|
|
90
|
-
})
|
|
101
|
+
});
|
|
102
|
+
const listViewConversionContext = {
|
|
103
|
+
componentConfigurations: data.components,
|
|
104
|
+
componentSchemas: components,
|
|
105
|
+
contentTypeSchemas: schemas
|
|
106
|
+
};
|
|
107
|
+
return {
|
|
108
|
+
edit,
|
|
109
|
+
list,
|
|
110
|
+
listViewConversionContext
|
|
111
|
+
};
|
|
112
|
+
}, [
|
|
113
|
+
data,
|
|
114
|
+
isLoading,
|
|
115
|
+
schemas,
|
|
116
|
+
schema,
|
|
117
|
+
components
|
|
118
|
+
]);
|
|
119
|
+
React__namespace.useEffect(()=>{
|
|
120
|
+
if (resolvedLayouts) {
|
|
121
|
+
stableLayoutsByModelRef.current.set(model, resolvedLayouts);
|
|
122
|
+
}
|
|
123
|
+
}, [
|
|
124
|
+
model,
|
|
125
|
+
resolvedLayouts
|
|
126
|
+
]);
|
|
127
|
+
const stableLayouts = resolvedLayouts ?? stableLayoutsByModelRef.current.get(model) ?? null;
|
|
128
|
+
const editLayout = React__namespace.useMemo(()=>stableLayouts?.edit ?? {
|
|
91
129
|
layout: [],
|
|
92
130
|
components: {},
|
|
93
131
|
metadatas: {},
|
|
94
132
|
options: {},
|
|
95
133
|
settings: DEFAULT_SETTINGS
|
|
96
134
|
}, [
|
|
97
|
-
|
|
98
|
-
isLoading,
|
|
99
|
-
schemas,
|
|
100
|
-
schema,
|
|
101
|
-
components
|
|
135
|
+
stableLayouts
|
|
102
136
|
]);
|
|
103
|
-
const listLayout = React__namespace.useMemo(()=>{
|
|
104
|
-
return data && !isLoading ? formatListLayout(data, {
|
|
105
|
-
schemas,
|
|
106
|
-
schema,
|
|
107
|
-
components
|
|
108
|
-
}) : {
|
|
137
|
+
const listLayout = React__namespace.useMemo(()=>stableLayouts?.list ?? {
|
|
109
138
|
layout: [],
|
|
110
139
|
metadatas: {},
|
|
111
140
|
options: {},
|
|
112
141
|
settings: DEFAULT_SETTINGS
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
data,
|
|
116
|
-
isLoading,
|
|
117
|
-
schemas,
|
|
118
|
-
schema,
|
|
119
|
-
components
|
|
142
|
+
}, [
|
|
143
|
+
stableLayouts
|
|
120
144
|
]);
|
|
121
145
|
const { layout: edit } = React__namespace.useMemo(()=>runHookWaterfall(hooks.HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {
|
|
122
146
|
layout: editLayout,
|
|
@@ -126,21 +150,7 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
|
126
150
|
query,
|
|
127
151
|
runHookWaterfall
|
|
128
152
|
]);
|
|
129
|
-
const listViewConversionContext =
|
|
130
|
-
if (!data || isLoading) {
|
|
131
|
-
return null;
|
|
132
|
-
}
|
|
133
|
-
return {
|
|
134
|
-
componentConfigurations: data.components,
|
|
135
|
-
componentSchemas: components,
|
|
136
|
-
contentTypeSchemas: schemas
|
|
137
|
-
};
|
|
138
|
-
}, [
|
|
139
|
-
data,
|
|
140
|
-
isLoading,
|
|
141
|
-
components,
|
|
142
|
-
schemas
|
|
143
|
-
]);
|
|
153
|
+
const listViewConversionContext = stableLayouts?.listViewConversionContext ?? null;
|
|
144
154
|
return {
|
|
145
155
|
error,
|
|
146
156
|
isLoading,
|
|
@@ -187,15 +197,20 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
|
187
197
|
return panels;
|
|
188
198
|
}, []);
|
|
189
199
|
const componentEditAttributes = Object.entries(data.components).reduce((acc, [uid, configuration])=>{
|
|
200
|
+
const componentSchema = components[uid];
|
|
201
|
+
// Persisted configuration can reference component UIDs absent from `/init`.
|
|
202
|
+
if (!componentSchema) {
|
|
203
|
+
return acc;
|
|
204
|
+
}
|
|
190
205
|
acc[uid] = {
|
|
191
|
-
layout: convertEditLayoutToFieldLayouts(configuration.layouts.edit,
|
|
206
|
+
layout: convertEditLayoutToFieldLayouts(configuration.layouts.edit, componentSchema.attributes, configuration.metadatas, {
|
|
192
207
|
configurations: data.components,
|
|
193
208
|
schemas: components
|
|
194
209
|
}),
|
|
195
210
|
settings: {
|
|
196
211
|
...configuration.settings,
|
|
197
|
-
icon:
|
|
198
|
-
displayName:
|
|
212
|
+
icon: componentSchema.info.icon,
|
|
213
|
+
displayName: componentSchema.info.displayName
|
|
199
214
|
}
|
|
200
215
|
};
|
|
201
216
|
return acc;
|
|
@@ -212,7 +227,7 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
|
212
227
|
metadatas: editMetadatas,
|
|
213
228
|
settings: {
|
|
214
229
|
...data.contentType.settings,
|
|
215
|
-
displayName: schema?.info
|
|
230
|
+
displayName: schema?.info?.displayName
|
|
216
231
|
},
|
|
217
232
|
options: {
|
|
218
233
|
...schema?.options,
|
|
@@ -234,8 +249,12 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
|
234
249
|
if (!attribute) {
|
|
235
250
|
return null;
|
|
236
251
|
}
|
|
237
|
-
const
|
|
238
|
-
|
|
252
|
+
const fieldMetadata = metadatas[field.name];
|
|
253
|
+
if (!fieldMetadata) {
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
const { edit: metadata } = fieldMetadata;
|
|
257
|
+
const settings = attribute.type === 'component' && components ? components.configurations[attribute.component]?.settings ?? {} : {};
|
|
239
258
|
return {
|
|
240
259
|
attribute,
|
|
241
260
|
disabled: !metadata.editable,
|
|
@@ -280,7 +299,7 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
|
280
299
|
layout: listAttributes,
|
|
281
300
|
settings: {
|
|
282
301
|
...data.contentType.settings,
|
|
283
|
-
displayName: schema?.info
|
|
302
|
+
displayName: schema?.info?.displayName
|
|
284
303
|
},
|
|
285
304
|
metadatas: listMetadatas,
|
|
286
305
|
options: {
|
|
@@ -305,7 +324,10 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
|
305
324
|
return null;
|
|
306
325
|
}
|
|
307
326
|
const metadata = metadatas[name];
|
|
308
|
-
|
|
327
|
+
if (!metadata) {
|
|
328
|
+
return null;
|
|
329
|
+
}
|
|
330
|
+
const settings = attribute.type === 'component' && components ? components.configurations[attribute.component]?.settings ?? {} : {};
|
|
309
331
|
return {
|
|
310
332
|
attribute,
|
|
311
333
|
label: metadata.label ?? '',
|