Skip to content

Commit

Permalink
Merge pull request #95 from contentstack/feature/entry-field-support-…
Browse files Browse the repository at this point in the history
…in-rte

Feature/entry field support in rte
  • Loading branch information
Nilesh-y authored May 13, 2024
2 parents 745ec4f + dadc8e0 commit d19a827
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/RTE/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ export class RTEPlugin {
break;
}

case "hoveringToolbarOptions": {
this.pluginMetaData.registry.hoveringToolbarOptions = {
autoWidth: value?.autoWidth
}
break;
}

case "elementType": {
const isInline =
(typeof value === "string" && value === "inline") ||
Expand Down
7 changes: 7 additions & 0 deletions src/RTE/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,15 @@ type IDynamicFunction = (
| Exclude<IElementTypeOptions, "text">
| Exclude<IElementTypeOptions, "text">[];

type IHoveringToolbarOptions = {
autoWidth?: boolean;
}
export declare interface IConfig {
title: string;
icon: React.ReactElement | null;
display: IDisplayOnOptions | IDisplayOnOptions[];
elementType: IElementTypeOptions | IElementTypeOptions[] | IDynamicFunction;
hoveringToolbarOptions?: IHoveringToolbarOptions;
render?: (...params: any) => ReactElement;
shouldOverride?: (element: IRteElementType) => boolean;
}
Expand All @@ -230,6 +234,9 @@ export declare interface IRegistry {
inMainToolbar: boolean;
inHoveringToolbar: boolean;
};
hoveringToolbarOptions?: {
autoWidth: true;
}
isContentstackElement: boolean;
beforeChildrenRender?: (...params: any) => any;
beforeElementRender?: (...params: any) => any;
Expand Down
2 changes: 2 additions & 0 deletions src/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Field from "./field";
import {
IFieldInitData,
IFieldModifierLocationInitData,
IRTEInitData,
ISidebarInitData,
} from "./types";
import { Entry as EntryType } from "../src/types/entry.types";
Expand Down Expand Up @@ -35,6 +36,7 @@ class Entry {
initializationData:
| IFieldInitData
| ISidebarInitData
| IRTEInitData
| IFieldModifierLocationInitData,
connection: typeof postRobot,
emitter: EventEmitter,
Expand Down
13 changes: 13 additions & 0 deletions src/stack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ContentType from './api/content-type/index';
import { onData, onError } from "../utils/utils";
import { BranchDetail, GetAllStacksOptions, StackAdditionalData, StackDetail, StackSearchQuery } from '../types/stack.types';
import { IManagementTokenDetails } from '../types';
import { GenericObjectType } from "../types/common.types";


/**
Expand Down Expand Up @@ -272,6 +273,18 @@ class Stack {
getCurrentBranch(): BranchDetail | null {
return this._currentBranch;
}

/**
* Returns variant groups details.
* @returns variant groups details.
*/
getVariantById(variant_uid:string) {
if (!variant_uid) {
return Promise.reject(new Error('variant uid is required'));
}
const options = { params: {uid : variant_uid}, action: 'getVariantById' };
return this._connection.sendToParent('stackQuery', options).then(onData).catch(onError);
}
}

export default Stack;
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ export declare interface IFullPageLocationInitData extends ICommonInitData {
export declare interface IRTEInitData extends ICommonInitData {
config?: GenericObjectType;
type: LocationType.RTE;
entry: Entry;
content_type: ContentType;
locale: string;
}

export declare interface IAppConfigInitData extends ICommonInitData {
Expand Down
4 changes: 3 additions & 1 deletion src/types/entry.types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Field from "../field";
import { AnyProperty } from "./common.types";
import { AnyProperty, GenericObjectType } from "./common.types";

export declare interface IGetFieldOptions {
/**
Expand Down Expand Up @@ -47,4 +47,6 @@ export interface Entry extends AnyProperty {
publish_details: Array<any>;
locale: string;
url?: string;
variant_uid?: string;
_variant?: GenericObjectType
}
10 changes: 10 additions & 0 deletions src/uiLocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
IDashboardWidget,
IFieldModifierLocation,
IFullPageLocation,
IRTEInitData,
ISidebarWidget,
InitializationData,
LocationType,
Expand Down Expand Up @@ -108,6 +109,7 @@ class UiLocation {
SidebarWidget: ISidebarWidget | null;
CustomField: ICustomField | null;
RTEPlugin: IRTEPluginInitializer | null;
RTELocation: GenericObjectType | null;
AppConfigWidget: IAppConfigWidget | null;
AssetSidebarWidget: AssetSidebarWidget | null;
FullPage: IFullPageLocation | null;
Expand Down Expand Up @@ -144,6 +146,7 @@ class UiLocation {
CustomField: null,
SidebarWidget: null,
RTEPlugin: null,
RTELocation: null,
AppConfigWidget: null,
AssetSidebarWidget: null,
FullPage: null,
Expand Down Expand Up @@ -216,6 +219,13 @@ class UiLocation {
case LocationType.RTE: {
import("./RTE").then(({ rtePluginInitializer }) => {
this.location.RTEPlugin = rtePluginInitializer;
this.location.RTELocation = {
entry: new Entry(
initializationData as IRTEInitData,
postRobot,
emitter
),
};
});
break;
}
Expand Down

0 comments on commit d19a827

Please sign in to comment.