{"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,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