@craftercms/studio-ui
Version:
Services, components, models & utils to build CrafterCMS authoring extensions.
230 lines (228 loc) • 11.1 kB
TypeScript
/*
* Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { BaseItem, DetailedItem, ItemActionsMap, ItemStateMap, LegacyItem, SandboxItem } from '../models/Item';
import { ContentType } from '../models/ContentType';
import LookupTable from '../models/LookupTable';
import ContentInstance from '../models/ContentInstance';
import { SystemType } from '../models/SystemType';
import { PublishingTargets } from '../models';
import { Dispatch } from 'react';
import { AnyAction } from 'redux';
export declare function isEditableAsset(path: string): boolean;
export declare function isAsset(path: string): boolean;
export declare function isCode(path: string): boolean;
export declare function isImage(path: string): boolean;
export declare function isItemLockedForMe(item: DetailedItem | SandboxItem | LegacyItem, username: string): boolean;
export declare function isBlobUrl(url: string): boolean;
/**
* TODO: Remove?
* Returns the boolean intersection of editMode, lock status and the item's edit permission
*/
export declare function getComputedEditMode({
item,
username,
editMode
}: {
item: DetailedItem;
username: string;
editMode: boolean;
}): boolean;
export declare function getSystemTypeFromPath(path: string): SystemType;
export declare function parseLegacyItemToBaseItem(item: LegacyItem): BaseItem;
export declare function parseLegacyItemToSandBoxItem(item: LegacyItem): SandboxItem;
export declare function parseLegacyItemToSandBoxItem(item: LegacyItem[]): SandboxItem[];
export declare function parseLegacyItemToDetailedItem(item: LegacyItem): DetailedItem;
export declare function parseLegacyItemToDetailedItem(item: LegacyItem[]): DetailedItem[];
export declare function parseSandBoxItemToDetailedItem(item: SandboxItem): DetailedItem;
export declare function parseSandBoxItemToDetailedItem(item: SandboxItem[]): DetailedItem[];
export declare function parseSandBoxItemToDetailedItem(
item: SandboxItem,
detailedItemComplement: Pick<DetailedItem, 'live' | 'staging'>
): DetailedItem;
export declare function parseSandBoxItemToDetailedItem(
item: SandboxItem[],
detailedItemComplementByPath: LookupTable<Pick<DetailedItem, 'live' | 'staging'>>
): DetailedItem[];
/**
* doc {XMLDocument}
* path {string}
* contentTypesLookup {LookupTable<ContentType>}
* instanceLookup {LookupTable<ContentInstance>}
* unflattenedPaths {LookupTable<ContentInstance>} A lookup table directly completed/mutated by this function indexed by path of those objects that are incomplete/unflattened
*/
export declare function parseContentXML(
doc: XMLDocument,
path: string,
contentTypesLookup: LookupTable<ContentType>,
instanceLookup: LookupTable<ContentInstance>,
unflattenedPaths?: LookupTable<ContentInstance>
): ContentInstance;
export interface ModelHierarchyDescriptor {
modelId: string;
parentId: string;
parentContainerFieldPath: string;
parentContainerFieldIndex: string | number;
children: Array<string>;
}
export type ModelHierarchyMap = LookupTable<ModelHierarchyDescriptor>;
export declare const createModelHierarchyDescriptor: (
modelId?: ModelHierarchyDescriptor['modelId'],
parentId?: ModelHierarchyDescriptor['parentId'],
parentContainerFieldPath?: ModelHierarchyDescriptor['parentContainerFieldPath'],
parentContainerFieldIndex?: ModelHierarchyDescriptor['parentContainerFieldIndex'],
children?: ModelHierarchyDescriptor['children']
) => ModelHierarchyDescriptor;
export declare function createModelHierarchyDescriptorMap(
normalizedModels: LookupTable<ContentInstance>,
contentTypes: LookupTable<ContentType>
): ModelHierarchyMap;
/**
* Returns an array with the ids of the direct descendants of a given model
*/
export declare function createChildModelIdList(
model: ContentInstance,
contentTypes: LookupTable<ContentType>
): string[];
/**
* Returns a lookup table as `{ [modelId]: [childModelId1, childModelId2, ...], ... }`
*/
export declare function createChildModelLookup(
models: LookupTable<ContentInstance>,
contentTypes: LookupTable<ContentType>
): LookupTable<string[]>;
export declare function normalizeModelsLookup(models: LookupTable<ContentInstance>): LookupTable<ContentInstance>;
export declare function normalizeModel(model: ContentInstance): ContentInstance;
export declare function denormalizeModel(
normalized: ContentInstance,
modelLookup: LookupTable<ContentInstance>
): ContentInstance;
export declare function getNumOfMenuOptionsForItem(item: DetailedItem): number;
export declare const isNewState: (value: number) => boolean;
export declare const isModifiedState: (value: number) => boolean;
export declare const isDeletedState: (value: number) => boolean;
export declare const isLockedState: (value: number) => boolean;
export declare const isSystemProcessingState: (value: number) => boolean;
export declare const isSubmittedState: (value: number) => boolean;
export declare const isScheduledState: (value: number) => boolean;
export declare const isPublishingState: (value: number) => boolean;
export declare const isSubmittedToStaging: (value: number) => boolean;
export declare const isSubmittedToLive: (value: number) => boolean;
export declare const isStaged: (value: number) => boolean;
export declare const isLive: (value: number) => boolean;
export declare const isDisabled: (value: number) => boolean;
export declare const isTranslationUpToDateState: (value: number) => boolean;
export declare const isTranslationPendingState: (value: number) => boolean;
export declare const isTranslationInProgressState: (value: number) => boolean;
export declare const createItemStateMap: (status: number) => ItemStateMap;
export declare const hasReadAction: (value: number) => boolean;
export declare const hasCopyAction: (value: number) => boolean;
export declare const hasReadHistoryAction: (value: number) => boolean;
export declare const hasGetDependenciesAction: (value: number) => boolean;
export declare const hasPublishRequestAction: (value: number) => boolean;
export declare const hasCreateAction: (value: number) => boolean;
export declare const hasPasteAction: (value: number) => boolean;
export declare const hasEditAction: (value: number) => boolean;
export declare const hasRenameAction: (value: number) => boolean;
export declare const hasCutAction: (value: number) => boolean;
export declare const hasUploadAction: (value: number) => boolean;
export declare const hasDuplicateAction: (value: number) => boolean;
export declare const hasChangeTypeAction: (value: number) => boolean;
export declare const hasRevertAction: (value: number) => boolean;
export declare const hasEditControllerAction: (value: number) => boolean;
export declare const hasEditTemplateAction: (value: number) => boolean;
export declare const hasCreateFolderAction: (value: number) => boolean;
export declare const hasContentDeleteAction: (value: number) => boolean;
export declare const hasDeleteControllerAction: (value: number) => boolean;
export declare const hasDeleteTemplateAction: (value: number) => boolean;
export declare const hasPublishAction: (value: number) => boolean;
export declare const hasApprovePublishAction: (value: number) => boolean;
export declare const hasSchedulePublishAction: (value: number) => boolean;
export declare const hasPublishRejectAction: (value: number) => boolean;
export declare const hasUnlockAction: (value: number) => boolean;
export declare const createItemActionMap: (availableActions: number) => ItemActionsMap;
/**
* Given an item lookup table, tries to find the path with and without the "/index.xml" portion of the path.
* This reconciles path differences when working with pages between folder and index (i.e. /site/website vs /site/website/index.xml),
* which refer to the same item in most contexts.
* path {string} The path to look for
* lookupTable {Record<string, T>} The map-like object containing all items in which to look the path up
* @returns {T} The item if found, undefined otherwise
**/
export declare function lookupItemByPath<T = DetailedItem>(path: string, lookupTable: LookupTable<T>): T;
export declare function modelsToLookup(models: ContentInstance[]): LookupTable<ContentInstance>;
export declare function createPathIdMap(models: LookupTable<ContentInstance>): LookupTable<string>;
export declare function getEditorMode(mimeType: string): 'ftl' | 'groovy' | 'javascript' | 'css' | 'text';
export declare function prepareVirtualItemProps(item: SandboxItem): SandboxItem;
export declare function prepareVirtualItemProps(item: DetailedItem): DetailedItem;
export declare function prepareVirtualItemProps(item: SandboxItem | DetailedItem): SandboxItem | DetailedItem;
export declare function getDateScheduled(item: DetailedItem): string;
export declare function getDatePublished(item: DetailedItem): string;
export declare function getComputedPublishingTarget(item: DetailedItem): PublishingTargets | null;
export declare function applyFolderNameRules(
name: string,
options?: {
allowBraces: boolean;
}
): string;
export declare function applyAssetNameRules(
name: string,
options?: {
allowBraces: boolean;
}
): string;
/**
* Utility to clean up a content name (pages/components/taxonomies). It removes any character that is not a lowercase
* letter, number, dash or underscore.
*/
export declare function applyContentNameRules(name: string): string;
export declare const openItemEditor: (
item: DetailedItem,
authoringBase: string,
siteId: string,
dispatch: Dispatch<AnyAction>,
onSaveSuccess?: AnyAction
) => void;
export declare function generateComponentBasePath(contentType: string): string;
export declare function generateComponentPath(modelId: string, contentType: string): string;
/**
* If the field is inherited, swaps the modelId and parentModelId with
* the inheritance parent's. */
export declare function getInheritanceParentIdsForField(
fieldId: string,
modelLookup: LookupTable<ContentInstance>,
modelId: string,
parentModelId: string,
modelIdByPath: LookupTable<string>,
hierarchyMap: ModelHierarchyMap
): {
modelId: string;
parentModelId: string;
};
export interface GeneratePlaceholderImageDataUrlArgs {
width: number;
height: number;
fillStyle: string;
textFillStyle: string;
text: string;
textPositionX: number;
textPositionY: number;
font: string;
textAlign: CanvasTextAlign;
textBaseline: CanvasTextBaseline;
}
export declare function generatePlaceholderImageDataUrl(
attributes?: Partial<GeneratePlaceholderImageDataUrlArgs>
): string;