chore: add and run prettier
This commit is contained in:
26
package-lock.json
generated
26
package-lock.json
generated
@@ -29,6 +29,7 @@
|
|||||||
"eslint-plugin-jsx-a11y": "^6.7.1",
|
"eslint-plugin-jsx-a11y": "^6.7.1",
|
||||||
"eslint-plugin-react": "^7.33.2",
|
"eslint-plugin-react": "^7.33.2",
|
||||||
"eslint-plugin-react-hooks": "^4.6.0",
|
"eslint-plugin-react-hooks": "^4.6.0",
|
||||||
|
"prettier": "^3.2.5",
|
||||||
"typescript": "^5.1.6",
|
"typescript": "^5.1.6",
|
||||||
"vite": "^5.1.0",
|
"vite": "^5.1.0",
|
||||||
"vite-tsconfig-paths": "^4.2.1"
|
"vite-tsconfig-paths": "^4.2.1"
|
||||||
@@ -2619,6 +2620,21 @@
|
|||||||
"node": ">=6"
|
"node": ">=6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@remix-run/dev/node_modules/prettier": {
|
||||||
|
"version": "2.8.8",
|
||||||
|
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz",
|
||||||
|
"integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==",
|
||||||
|
"dev": true,
|
||||||
|
"bin": {
|
||||||
|
"prettier": "bin-prettier.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10.13.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/prettier/prettier?sponsor=1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@remix-run/dev/node_modules/tsconfig-paths": {
|
"node_modules/@remix-run/dev/node_modules/tsconfig-paths": {
|
||||||
"version": "4.2.0",
|
"version": "4.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-4.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-4.2.0.tgz",
|
||||||
@@ -11013,15 +11029,15 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/prettier": {
|
"node_modules/prettier": {
|
||||||
"version": "2.8.8",
|
"version": "3.2.5",
|
||||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz",
|
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.2.5.tgz",
|
||||||
"integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==",
|
"integrity": "sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"bin": {
|
"bin": {
|
||||||
"prettier": "bin-prettier.js"
|
"prettier": "bin/prettier.cjs"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10.13.0"
|
"node": ">=14"
|
||||||
},
|
},
|
||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://github.com/prettier/prettier?sponsor=1"
|
"url": "https://github.com/prettier/prettier?sponsor=1"
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
"eslint-plugin-jsx-a11y": "^6.7.1",
|
"eslint-plugin-jsx-a11y": "^6.7.1",
|
||||||
"eslint-plugin-react": "^7.33.2",
|
"eslint-plugin-react": "^7.33.2",
|
||||||
"eslint-plugin-react-hooks": "^4.6.0",
|
"eslint-plugin-react-hooks": "^4.6.0",
|
||||||
|
"prettier": "^3.2.5",
|
||||||
"typescript": "^5.1.6",
|
"typescript": "^5.1.6",
|
||||||
"vite": "^5.1.0",
|
"vite": "^5.1.0",
|
||||||
"vite-tsconfig-paths": "^4.2.1"
|
"vite-tsconfig-paths": "^4.2.1"
|
||||||
|
|||||||
@@ -8,8 +8,8 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
root: true,
|
root: true,
|
||||||
parserOptions: {
|
parserOptions: {
|
||||||
ecmaVersion: 'latest',
|
ecmaVersion: "latest",
|
||||||
sourceType: 'module',
|
sourceType: "module",
|
||||||
ecmaFeatures: {
|
ecmaFeatures: {
|
||||||
jsx: true,
|
jsx: true,
|
||||||
},
|
},
|
||||||
@@ -19,38 +19,38 @@ module.exports = {
|
|||||||
commonjs: true,
|
commonjs: true,
|
||||||
es6: true,
|
es6: true,
|
||||||
},
|
},
|
||||||
ignorePatterns: ['build/**/*', 'node_modules/**/*', 'public/**/*'],
|
ignorePatterns: ["build/**/*", "node_modules/**/*", "public/**/*"],
|
||||||
|
|
||||||
// Base config
|
// Base config
|
||||||
extends: ['eslint:recommended'],
|
extends: ["eslint:recommended"],
|
||||||
|
|
||||||
overrides: [
|
overrides: [
|
||||||
// React
|
// React
|
||||||
{
|
{
|
||||||
files: ['**/*.{js,jsx,ts,tsx}'],
|
files: ["**/*.{js,jsx,ts,tsx}"],
|
||||||
plugins: ['react', 'jsx-a11y'],
|
plugins: ["react", "jsx-a11y"],
|
||||||
rules: {
|
rules: {
|
||||||
'react/jsx-uses-vars': 'error',
|
"react/jsx-uses-vars": "error",
|
||||||
'react/jsx-uses-react': 'error',
|
"react/jsx-uses-react": "error",
|
||||||
},
|
},
|
||||||
extends: [
|
extends: [
|
||||||
'plugin:react/recommended',
|
"plugin:react/recommended",
|
||||||
'plugin:react/jsx-runtime',
|
"plugin:react/jsx-runtime",
|
||||||
'plugin:react-hooks/recommended',
|
"plugin:react-hooks/recommended",
|
||||||
'plugin:jsx-a11y/recommended',
|
"plugin:jsx-a11y/recommended",
|
||||||
],
|
],
|
||||||
settings: {
|
settings: {
|
||||||
react: {
|
react: {
|
||||||
version: 'detect',
|
version: "detect",
|
||||||
},
|
},
|
||||||
formComponents: ['Form'],
|
formComponents: ["Form"],
|
||||||
linkComponents: [
|
linkComponents: [
|
||||||
{ name: 'Link', linkAttribute: 'to' },
|
{ name: "Link", linkAttribute: "to" },
|
||||||
{ name: 'NavLink', linkAttribute: 'to' },
|
{ name: "NavLink", linkAttribute: "to" },
|
||||||
],
|
],
|
||||||
'import/resolver': {
|
"import/resolver": {
|
||||||
typescript: {
|
typescript: {
|
||||||
project: './remix/tsconfig.json',
|
project: "./remix/tsconfig.json",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -58,14 +58,14 @@ module.exports = {
|
|||||||
|
|
||||||
// Typescript
|
// Typescript
|
||||||
{
|
{
|
||||||
files: ['**/*.{ts,tsx}'],
|
files: ["**/*.{ts,tsx}"],
|
||||||
plugins: ['@typescript-eslint', 'import'],
|
plugins: ["@typescript-eslint", "import"],
|
||||||
parser: '@typescript-eslint/parser',
|
parser: "@typescript-eslint/parser",
|
||||||
settings: {
|
settings: {
|
||||||
'import/internal-regex': '^~/',
|
"import/internal-regex": "^~/",
|
||||||
'import/resolver': {
|
"import/resolver": {
|
||||||
node: {
|
node: {
|
||||||
extensions: ['.ts', '.tsx'],
|
extensions: [".ts", ".tsx"],
|
||||||
},
|
},
|
||||||
typescript: {
|
typescript: {
|
||||||
alwaysTryTypes: true,
|
alwaysTryTypes: true,
|
||||||
@@ -73,18 +73,18 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
extends: [
|
extends: [
|
||||||
'plugin:@typescript-eslint/recommended',
|
"plugin:@typescript-eslint/recommended",
|
||||||
'plugin:import/recommended',
|
"plugin:import/recommended",
|
||||||
'plugin:import/typescript',
|
"plugin:import/typescript",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
||||||
// Node
|
// Node
|
||||||
{
|
{
|
||||||
files: ['.eslintrc.cjs'],
|
files: [".eslintrc.cjs"],
|
||||||
env: {
|
env: {
|
||||||
node: true,
|
node: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
}
|
||||||
|
|||||||
11
remix/.prettierignore
Normal file
11
remix/.prettierignore
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# Directories
|
||||||
|
build
|
||||||
|
public
|
||||||
|
|
||||||
|
# Files
|
||||||
|
.eslintrc.cjs
|
||||||
|
.prettierignore
|
||||||
|
package.json
|
||||||
|
package-lock.json
|
||||||
|
prettier.config.cjs
|
||||||
|
tsconfig.json
|
||||||
@@ -4,22 +4,22 @@ import {
|
|||||||
Help,
|
Help,
|
||||||
Line,
|
Line,
|
||||||
TextInput,
|
TextInput,
|
||||||
} from "@contentstack/venus-components";
|
} from "@contentstack/venus-components"
|
||||||
import { ChangeEvent, useState } from "react";
|
import { ChangeEvent, useState } from "react"
|
||||||
import { ImageVaultDAMConfig } from "~/utils/imagevault";
|
import { ImageVaultDAMConfig } from "~/utils/imagevault"
|
||||||
|
|
||||||
import type { IInstallationData } from "@contentstack/app-sdk/dist/src/types";
|
import type { IInstallationData } from "@contentstack/app-sdk/dist/src/types"
|
||||||
|
|
||||||
export type ConfigFormProps = {
|
export type ConfigFormProps = {
|
||||||
values: Partial<ImageVaultDAMConfig>;
|
values: Partial<ImageVaultDAMConfig>
|
||||||
setInstallationData: (data: IInstallationData) => void;
|
setInstallationData: (data: IInstallationData) => void
|
||||||
};
|
}
|
||||||
|
|
||||||
export default function ConfigForm({
|
export default function ConfigForm({
|
||||||
values,
|
values,
|
||||||
setInstallationData,
|
setInstallationData,
|
||||||
}: ConfigFormProps) {
|
}: ConfigFormProps) {
|
||||||
const [finalValues, setFinalValues] = useState(values);
|
const [finalValues, setFinalValues] = useState(values)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{ display: "grid", gap: "18px", margin: "18px" }}>
|
<div style={{ display: "grid", gap: "18px", margin: "18px" }}>
|
||||||
@@ -37,7 +37,7 @@ export default function ConfigForm({
|
|||||||
setFinalValues((prev) => ({
|
setFinalValues((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
baseUrl: evt.target.value,
|
baseUrl: evt.target.value,
|
||||||
}));
|
}))
|
||||||
|
|
||||||
setInstallationData({
|
setInstallationData({
|
||||||
configuration: {
|
configuration: {
|
||||||
@@ -45,7 +45,7 @@ export default function ConfigForm({
|
|||||||
baseUrl: evt.target.value,
|
baseUrl: evt.target.value,
|
||||||
},
|
},
|
||||||
serverConfiguration: {},
|
serverConfiguration: {},
|
||||||
});
|
})
|
||||||
}}
|
}}
|
||||||
required={true}
|
required={true}
|
||||||
willBlurOnEsc={true}
|
willBlurOnEsc={true}
|
||||||
@@ -76,7 +76,7 @@ export default function ConfigForm({
|
|||||||
setFinalValues((prev) => ({
|
setFinalValues((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
formatId: evt.target.value,
|
formatId: evt.target.value,
|
||||||
}));
|
}))
|
||||||
|
|
||||||
setInstallationData({
|
setInstallationData({
|
||||||
configuration: {
|
configuration: {
|
||||||
@@ -84,7 +84,7 @@ export default function ConfigForm({
|
|||||||
formatId: evt.target.value,
|
formatId: evt.target.value,
|
||||||
},
|
},
|
||||||
serverConfiguration: {},
|
serverConfiguration: {},
|
||||||
});
|
})
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Field>
|
</Field>
|
||||||
@@ -109,7 +109,7 @@ export default function ConfigForm({
|
|||||||
setFinalValues((prev) => ({
|
setFinalValues((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
imageVaultUrl: evt.target.value,
|
imageVaultUrl: evt.target.value,
|
||||||
}));
|
}))
|
||||||
|
|
||||||
setInstallationData({
|
setInstallationData({
|
||||||
configuration: {
|
configuration: {
|
||||||
@@ -117,10 +117,10 @@ export default function ConfigForm({
|
|||||||
imageVaultUrl: evt.target.value,
|
imageVaultUrl: evt.target.value,
|
||||||
},
|
},
|
||||||
serverConfiguration: {},
|
serverConfiguration: {},
|
||||||
});
|
})
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Field>
|
</Field>
|
||||||
</div>
|
</div>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,5 +8,5 @@ export default function Disclaimer() {
|
|||||||
save the entry at least once with a title before choosing an image.
|
save the entry at least once with a title before choosing an image.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ModalBody, ModalHeader } from "@contentstack/venus-components";
|
import { ModalBody, ModalHeader } from "@contentstack/venus-components"
|
||||||
|
|
||||||
export default function FullSizeImage({
|
export default function FullSizeImage({
|
||||||
title,
|
title,
|
||||||
@@ -7,11 +7,11 @@ export default function FullSizeImage({
|
|||||||
alt,
|
alt,
|
||||||
aspectRatio,
|
aspectRatio,
|
||||||
}: {
|
}: {
|
||||||
title: string;
|
title: string
|
||||||
onClose: () => void;
|
onClose: () => void
|
||||||
imageUrl: string;
|
imageUrl: string
|
||||||
alt: string;
|
alt: string
|
||||||
aspectRatio: number;
|
aspectRatio: number
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -37,5 +37,5 @@ export default function FullSizeImage({
|
|||||||
/>
|
/>
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
</>
|
</>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useState, useEffect, ChangeEvent } from "react";
|
import { useState, useEffect, ChangeEvent } from "react"
|
||||||
import {
|
import {
|
||||||
ModalFooter,
|
ModalFooter,
|
||||||
ModalBody,
|
ModalBody,
|
||||||
@@ -8,59 +8,59 @@ import {
|
|||||||
Field as FieldComponent,
|
Field as FieldComponent,
|
||||||
FieldLabel,
|
FieldLabel,
|
||||||
TextInput,
|
TextInput,
|
||||||
} from "@contentstack/venus-components";
|
} from "@contentstack/venus-components"
|
||||||
|
|
||||||
import type { InsertResponse } from "~/types/imagevault";
|
import type { InsertResponse } from "~/types/imagevault"
|
||||||
|
|
||||||
type ImageEditModalProps = {
|
type ImageEditModalProps = {
|
||||||
fieldData: InsertResponse;
|
fieldData: InsertResponse
|
||||||
setData: (data: InsertResponse) => void;
|
setData: (data: InsertResponse) => void
|
||||||
closeModal: () => void;
|
closeModal: () => void
|
||||||
};
|
}
|
||||||
|
|
||||||
export default function ImageEditModal({
|
export default function ImageEditModal({
|
||||||
fieldData,
|
fieldData,
|
||||||
closeModal,
|
closeModal,
|
||||||
setData,
|
setData,
|
||||||
}: ImageEditModalProps) {
|
}: ImageEditModalProps) {
|
||||||
const [altText, setAltText] = useState("");
|
const [altText, setAltText] = useState("")
|
||||||
const [caption, setCaption] = useState("");
|
const [caption, setCaption] = useState("")
|
||||||
|
|
||||||
const assetUrl = fieldData.MediaConversions[0].Url;
|
const assetUrl = fieldData.MediaConversions[0].Url
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (fieldData.Metadata && fieldData.Metadata.length) {
|
if (fieldData.Metadata && fieldData.Metadata.length) {
|
||||||
const altText = fieldData.Metadata.find((meta) =>
|
const altText = fieldData.Metadata.find((meta) =>
|
||||||
meta.Name.includes("AltText_")
|
meta.Name.includes("AltText_")
|
||||||
)?.Value;
|
)?.Value
|
||||||
|
|
||||||
const caption = fieldData.Metadata.find((meta) =>
|
const caption = fieldData.Metadata.find((meta) =>
|
||||||
meta.Name.includes("Title_")
|
meta.Name.includes("Title_")
|
||||||
)?.Value;
|
)?.Value
|
||||||
|
|
||||||
setAltText(altText ?? "");
|
setAltText(altText ?? "")
|
||||||
setCaption(caption ?? "");
|
setCaption(caption ?? "")
|
||||||
}
|
}
|
||||||
}, [fieldData.Metadata]);
|
}, [fieldData.Metadata])
|
||||||
|
|
||||||
function handleSave() {
|
function handleSave() {
|
||||||
const metaData = fieldData.Metadata ?? [];
|
const metaData = fieldData.Metadata ?? []
|
||||||
|
|
||||||
const newMetadata = metaData.map((meta) => {
|
const newMetadata = metaData.map((meta) => {
|
||||||
if (meta.Name.includes("AltText_")) {
|
if (meta.Name.includes("AltText_")) {
|
||||||
return { ...meta, Value: altText };
|
return { ...meta, Value: altText }
|
||||||
}
|
}
|
||||||
if (meta.Name.includes("Title_")) {
|
if (meta.Name.includes("Title_")) {
|
||||||
return { ...meta, Value: caption };
|
return { ...meta, Value: caption }
|
||||||
}
|
}
|
||||||
return meta;
|
return meta
|
||||||
});
|
})
|
||||||
|
|
||||||
setData({
|
setData({
|
||||||
...fieldData,
|
...fieldData,
|
||||||
Metadata: newMetadata,
|
Metadata: newMetadata,
|
||||||
});
|
})
|
||||||
closeModal();
|
closeModal()
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -120,5 +120,5 @@ export default function ImageEditModal({
|
|||||||
</ButtonGroup>
|
</ButtonGroup>
|
||||||
</ModalFooter>
|
</ModalFooter>
|
||||||
</>
|
</>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +1,34 @@
|
|||||||
import { useCallback, useEffect, useState } from "react";
|
import { useCallback, useEffect, useState } from "react"
|
||||||
import { flushSync } from "react-dom";
|
import { flushSync } from "react-dom"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
AssetCardVertical,
|
AssetCardVertical,
|
||||||
Button,
|
Button,
|
||||||
FieldLabel,
|
FieldLabel,
|
||||||
cbModal,
|
cbModal,
|
||||||
} from "@contentstack/venus-components";
|
} from "@contentstack/venus-components"
|
||||||
import ImageEditModal from "./ImageEditModal";
|
import ImageEditModal from "./ImageEditModal"
|
||||||
import FullSizeImage from "./FullSizeImage";
|
import FullSizeImage from "./FullSizeImage"
|
||||||
import { isInsertResponse, openImageVault } from "~/utils/imagevault";
|
import { isInsertResponse, openImageVault } from "~/utils/imagevault"
|
||||||
|
|
||||||
import type { CbModalProps } from "@contentstack/venus-components/build/components/Modal/Modal";
|
import type { CbModalProps } from "@contentstack/venus-components/build/components/Modal/Modal"
|
||||||
import type UiLocation from "@contentstack/app-sdk/dist/src/uiLocation";
|
import type UiLocation from "@contentstack/app-sdk/dist/src/uiLocation"
|
||||||
import type { InsertResponse } from "~/types/imagevault";
|
import type { InsertResponse } from "~/types/imagevault"
|
||||||
import type {
|
import type {
|
||||||
EntryDataPublishDetails,
|
EntryDataPublishDetails,
|
||||||
ImageVaultDAMConfig,
|
ImageVaultDAMConfig,
|
||||||
} from "~/utils/imagevault";
|
} from "~/utils/imagevault"
|
||||||
import type { Lang } from "~/types/lang";
|
import type { Lang } from "~/types/lang"
|
||||||
|
|
||||||
export type ImageVaultDAMProps = {
|
export type ImageVaultDAMProps = {
|
||||||
sdk: UiLocation;
|
sdk: UiLocation
|
||||||
config: ImageVaultDAMConfig;
|
config: ImageVaultDAMConfig
|
||||||
initialData: InsertResponse | null;
|
initialData: InsertResponse | null
|
||||||
};
|
}
|
||||||
|
|
||||||
type DAMButtonProps = {
|
type DAMButtonProps = {
|
||||||
onClick: () => void;
|
onClick: () => void
|
||||||
};
|
}
|
||||||
|
|
||||||
function DAMButton({ onClick }: DAMButtonProps) {
|
function DAMButton({ onClick }: DAMButtonProps) {
|
||||||
return (
|
return (
|
||||||
@@ -45,27 +45,27 @@ function DAMButton({ onClick }: DAMButtonProps) {
|
|||||||
Choose a file
|
Choose a file
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
type MediaProps = {
|
type MediaProps = {
|
||||||
media: InsertResponse;
|
media: InsertResponse
|
||||||
onDelete: () => void;
|
onDelete: () => void
|
||||||
onEdit: () => void;
|
onEdit: () => void
|
||||||
};
|
}
|
||||||
|
|
||||||
function Media({ media, onDelete, onEdit }: MediaProps) {
|
function Media({ media, onDelete, onEdit }: MediaProps) {
|
||||||
// MediaConversions is an array but will only contain one object
|
// MediaConversions is an array but will only contain one object
|
||||||
const { Url, Height, FormatHeight, Width, FormatWidth, Name, AspectRatio } =
|
const { Url, Height, FormatHeight, Width, FormatWidth, Name, AspectRatio } =
|
||||||
media.MediaConversions[0];
|
media.MediaConversions[0]
|
||||||
|
|
||||||
const assetUrl = Url;
|
const assetUrl = Url
|
||||||
const title = media.Name;
|
const title = media.Name
|
||||||
const width = FormatWidth || Width;
|
const width = FormatWidth || Width
|
||||||
const height = FormatHeight || Height;
|
const height = FormatHeight || Height
|
||||||
const alt =
|
const alt =
|
||||||
media.Metadata?.find((meta) => meta.Name.includes("AltText_"))?.Value ||
|
media.Metadata?.find((meta) => meta.Name.includes("AltText_"))?.Value ||
|
||||||
Name;
|
Name
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div key={Url} style={{ fontFamily: "Inter" }}>
|
<div key={Url} style={{ fontFamily: "Inter" }}>
|
||||||
@@ -91,7 +91,7 @@ function Media({ media, onDelete, onEdit }: MediaProps) {
|
|||||||
title={Name}
|
title={Name}
|
||||||
aspectRatio={AspectRatio}
|
aspectRatio={AspectRatio}
|
||||||
/>
|
/>
|
||||||
);
|
)
|
||||||
},
|
},
|
||||||
modalProps: {
|
modalProps: {
|
||||||
size: "max",
|
size: "max",
|
||||||
@@ -106,12 +106,12 @@ function Media({ media, onDelete, onEdit }: MediaProps) {
|
|||||||
overlay: {},
|
overlay: {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
}
|
||||||
cbModal(cbModalProps);
|
cbModal(cbModalProps)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function ImageVaultDAM({
|
export default function ImageVaultDAM({
|
||||||
@@ -119,42 +119,42 @@ export default function ImageVaultDAM({
|
|||||||
config,
|
config,
|
||||||
initialData,
|
initialData,
|
||||||
}: ImageVaultDAMProps) {
|
}: ImageVaultDAMProps) {
|
||||||
const [media, setMedia] = useState<InsertResponse | null>(initialData);
|
const [media, setMedia] = useState<InsertResponse | null>(initialData)
|
||||||
|
|
||||||
const field = sdk.location.CustomField?.field;
|
const field = sdk.location.CustomField?.field
|
||||||
const frame = sdk.location.CustomField?.frame;
|
const frame = sdk.location.CustomField?.frame
|
||||||
const entry = sdk.location.CustomField?.entry;
|
const entry = sdk.location.CustomField?.entry
|
||||||
const stack = sdk.location.CustomField?.stack;
|
const stack = sdk.location.CustomField?.stack
|
||||||
|
|
||||||
const updateFrameHeight = useCallback(() => {
|
const updateFrameHeight = useCallback(() => {
|
||||||
if (frame?.updateHeight) {
|
if (frame?.updateHeight) {
|
||||||
// We need to recalculate the height of the iframe when an image is added.
|
// We need to recalculate the height of the iframe when an image is added.
|
||||||
// Cannot use flushSync inside useEffect.
|
// Cannot use flushSync inside useEffect.
|
||||||
setTimeout(() => frame.updateHeight(document.body.scrollHeight), 0);
|
setTimeout(() => frame.updateHeight(document.body.scrollHeight), 0)
|
||||||
}
|
}
|
||||||
}, [frame]);
|
}, [frame])
|
||||||
|
|
||||||
const handleMedia = useCallback(
|
const handleMedia = useCallback(
|
||||||
(result?: InsertResponse) => {
|
(result?: InsertResponse) => {
|
||||||
if (field && result) {
|
if (field && result) {
|
||||||
flushSync(() => {
|
flushSync(() => {
|
||||||
setMedia(result);
|
setMedia(result)
|
||||||
field.setData(result);
|
field.setData(result)
|
||||||
document.body.style.overflow = "hidden";
|
document.body.style.overflow = "hidden"
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
updateFrameHeight();
|
updateFrameHeight()
|
||||||
},
|
},
|
||||||
[field, updateFrameHeight]
|
[field, updateFrameHeight]
|
||||||
);
|
)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
updateFrameHeight();
|
updateFrameHeight()
|
||||||
}, [updateFrameHeight]);
|
}, [updateFrameHeight])
|
||||||
|
|
||||||
const handleEdit = useCallback(() => {
|
const handleEdit = useCallback(() => {
|
||||||
const fieldData = field?.getData() as InsertResponse;
|
const fieldData = field?.getData() as InsertResponse
|
||||||
if (isInsertResponse(fieldData)) {
|
if (isInsertResponse(fieldData)) {
|
||||||
cbModal({
|
cbModal({
|
||||||
// @ts-expect-error: Component is badly typed
|
// @ts-expect-error: Component is badly typed
|
||||||
@@ -168,12 +168,12 @@ export default function ImageVaultDAM({
|
|||||||
modalProps: {
|
modalProps: {
|
||||||
size: "max",
|
size: "max",
|
||||||
},
|
},
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
}, [field, handleMedia]);
|
}, [field, handleMedia])
|
||||||
|
|
||||||
if (!field || !frame || !entry || !stack) {
|
if (!field || !frame || !entry || !stack) {
|
||||||
return <p>Initializing custom field...</p>;
|
return <p>Initializing custom field...</p>
|
||||||
}
|
}
|
||||||
|
|
||||||
const entryData: EntryDataPublishDetails = {
|
const entryData: EntryDataPublishDetails = {
|
||||||
@@ -186,7 +186,7 @@ export default function ImageVaultDAM({
|
|||||||
entry.getField("title").getData().toString() ||
|
entry.getField("title").getData().toString() ||
|
||||||
`Untitled (${entry.content_type.uid})`,
|
`Untitled (${entry.content_type.uid})`,
|
||||||
uid: entry._data.uid,
|
uid: entry._data.uid,
|
||||||
};
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@@ -200,8 +200,8 @@ export default function ImageVaultDAM({
|
|||||||
<Media
|
<Media
|
||||||
media={media}
|
media={media}
|
||||||
onDelete={() => {
|
onDelete={() => {
|
||||||
setMedia(null);
|
setMedia(null)
|
||||||
handleMedia();
|
handleMedia()
|
||||||
}}
|
}}
|
||||||
onEdit={handleEdit}
|
onEdit={handleEdit}
|
||||||
/>
|
/>
|
||||||
@@ -212,10 +212,10 @@ export default function ImageVaultDAM({
|
|||||||
config,
|
config,
|
||||||
entryData,
|
entryData,
|
||||||
onSuccess: handleMedia,
|
onSuccess: handleMedia,
|
||||||
});
|
})
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,5 +7,5 @@ export default function InvalidConfig() {
|
|||||||
to run correctly.
|
to run correctly.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { RemixBrowser } from "@remix-run/react";
|
import { RemixBrowser } from "@remix-run/react"
|
||||||
import { startTransition, StrictMode } from "react";
|
import { startTransition, StrictMode } from "react"
|
||||||
import { hydrateRoot } from "react-dom/client";
|
import { hydrateRoot } from "react-dom/client"
|
||||||
|
|
||||||
startTransition(() => {
|
startTransition(() => {
|
||||||
hydrateRoot(
|
hydrateRoot(
|
||||||
@@ -8,5 +8,5 @@ startTransition(() => {
|
|||||||
<StrictMode>
|
<StrictMode>
|
||||||
<RemixBrowser />
|
<RemixBrowser />
|
||||||
</StrictMode>
|
</StrictMode>
|
||||||
);
|
)
|
||||||
});
|
})
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { EntryContext } from "@remix-run/node";
|
import type { EntryContext } from "@remix-run/node"
|
||||||
import { RemixServer } from "@remix-run/react";
|
import { RemixServer } from "@remix-run/react"
|
||||||
import { renderToString } from "react-dom/server";
|
import { renderToString } from "react-dom/server"
|
||||||
|
|
||||||
export default function handleRequest(
|
export default function handleRequest(
|
||||||
request: Request,
|
request: Request,
|
||||||
@@ -10,10 +10,10 @@ export default function handleRequest(
|
|||||||
) {
|
) {
|
||||||
let html = renderToString(
|
let html = renderToString(
|
||||||
<RemixServer context={remixContext} url={request.url} />
|
<RemixServer context={remixContext} url={request.url} />
|
||||||
);
|
)
|
||||||
html = "<!DOCTYPE html>\n" + html;
|
html = "<!DOCTYPE html>\n" + html
|
||||||
return new Response(html, {
|
return new Response(html, {
|
||||||
headers: { "Content-Type": "text/html" },
|
headers: { "Content-Type": "text/html" },
|
||||||
status: responseStatusCode,
|
status: responseStatusCode,
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,46 +1,46 @@
|
|||||||
import UiLocation from "@contentstack/app-sdk/dist/src/uiLocation";
|
import UiLocation from "@contentstack/app-sdk/dist/src/uiLocation"
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react"
|
||||||
|
|
||||||
export class SDKLoadingError extends Error {}
|
export class SDKLoadingError extends Error {}
|
||||||
|
|
||||||
export default function useApp() {
|
export default function useApp() {
|
||||||
const [, setError] = useState();
|
const [, setError] = useState()
|
||||||
const [sdk, setSdk] = useState<UiLocation>();
|
const [sdk, setSdk] = useState<UiLocation>()
|
||||||
const [config, setConfig] = useState<Record<string, string>>();
|
const [config, setConfig] = useState<Record<string, string>>()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function init() {
|
async function init() {
|
||||||
try {
|
try {
|
||||||
const ContentstackAppSDK = (await import("@contentstack/app-sdk"))
|
const ContentstackAppSDK = (await import("@contentstack/app-sdk"))
|
||||||
.default;
|
.default
|
||||||
const initSdk = await ContentstackAppSDK.init();
|
const initSdk = await ContentstackAppSDK.init()
|
||||||
setSdk(initSdk);
|
setSdk(initSdk)
|
||||||
|
|
||||||
const config = await initSdk.getConfig();
|
const config = await initSdk.getConfig()
|
||||||
setConfig(config);
|
setConfig(config)
|
||||||
|
|
||||||
const iframeWrapperRef = document.getElementById("field");
|
const iframeWrapperRef = document.getElementById("field")
|
||||||
window.iframeRef = iframeWrapperRef;
|
window.iframeRef = iframeWrapperRef
|
||||||
window.postRobot = initSdk.postRobot;
|
window.postRobot = initSdk.postRobot
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
let err: Error;
|
let err: Error
|
||||||
if (e instanceof Error) {
|
if (e instanceof Error) {
|
||||||
err = new SDKLoadingError(e.message);
|
err = new SDKLoadingError(e.message)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error boundaries do not support async functions. Workaround:
|
// Error boundaries do not support async functions. Workaround:
|
||||||
// https://github.com/vercel/next.js/discussions/50564#discussioncomment-6063866
|
// https://github.com/vercel/next.js/discussions/50564#discussioncomment-6063866
|
||||||
setError(() => {
|
setError(() => {
|
||||||
throw err;
|
throw err
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
init();
|
init()
|
||||||
}, [setSdk, setConfig]);
|
}, [setSdk, setConfig])
|
||||||
|
|
||||||
return {
|
return {
|
||||||
sdk,
|
sdk,
|
||||||
config,
|
config,
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import {
|
|||||||
Scripts,
|
Scripts,
|
||||||
ScrollRestoration,
|
ScrollRestoration,
|
||||||
useRouteError,
|
useRouteError,
|
||||||
} from '@remix-run/react';
|
} from "@remix-run/react"
|
||||||
import { SDKLoadingError } from './hooks/useApp';
|
import { SDKLoadingError } from "./hooks/useApp"
|
||||||
|
|
||||||
export function Layout({ children }: { children: React.ReactNode }) {
|
export function Layout({ children }: { children: React.ReactNode }) {
|
||||||
return (
|
return (
|
||||||
@@ -31,20 +31,20 @@ export function Layout({ children }: { children: React.ReactNode }) {
|
|||||||
<Scripts />
|
<Scripts />
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
return <Outlet />;
|
return <Outlet />
|
||||||
}
|
}
|
||||||
|
|
||||||
export function HydrateFallback() {
|
export function HydrateFallback() {
|
||||||
return <p>Loading...</p>;
|
return <p>Loading...</p>
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ErrorBoundary() {
|
export function ErrorBoundary() {
|
||||||
const error = useRouteError();
|
const error = useRouteError()
|
||||||
console.error(error);
|
console.error(error)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
@@ -68,5 +68,5 @@ export function ErrorBoundary() {
|
|||||||
<Scripts />
|
<Scripts />
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
import type { MetaFunction } from '@remix-run/node';
|
import type { MetaFunction } from "@remix-run/node"
|
||||||
|
|
||||||
export const meta: MetaFunction = () => {
|
export const meta: MetaFunction = () => {
|
||||||
return [
|
return [
|
||||||
{ title: 'DAM: ImageVault integration' },
|
{ title: "DAM: ImageVault integration" },
|
||||||
{
|
{
|
||||||
name: 'description',
|
name: "description",
|
||||||
content: 'Integration of ImageVault as a DAM for Contentstack',
|
content: "Integration of ImageVault as a DAM for Contentstack",
|
||||||
},
|
},
|
||||||
];
|
]
|
||||||
};
|
}
|
||||||
|
|
||||||
export default function Index() {
|
export default function Index() {
|
||||||
return null;
|
return null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import { Suspense, lazy } from "react";
|
import { Suspense, lazy } from "react"
|
||||||
import useApp from "~/hooks/useApp";
|
import useApp from "~/hooks/useApp"
|
||||||
|
|
||||||
const ConfigForm = lazy(() => import("~/components/ConfigForm"));
|
const ConfigForm = lazy(() => import("~/components/ConfigForm"))
|
||||||
|
|
||||||
export default function ConfigPage() {
|
export default function ConfigPage() {
|
||||||
const { sdk, config } = useApp();
|
const { sdk, config } = useApp()
|
||||||
|
|
||||||
const appConfigWidget = sdk?.location.AppConfigWidget;
|
const appConfigWidget = sdk?.location.AppConfigWidget
|
||||||
|
|
||||||
const setInstallationData = appConfigWidget?.installation.setInstallationData;
|
const setInstallationData = appConfigWidget?.installation.setInstallationData
|
||||||
|
|
||||||
if (!config) {
|
if (!config) {
|
||||||
return (
|
return (
|
||||||
@@ -17,7 +17,7 @@ export default function ConfigPage() {
|
|||||||
Could not fetch the current configuration, please try again later!
|
Could not fetch the current configuration, please try again later!
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!setInstallationData) {
|
if (!setInstallationData) {
|
||||||
@@ -27,12 +27,12 @@ export default function ConfigPage() {
|
|||||||
THe configuration cannot be updated right now, please try again later!
|
THe configuration cannot be updated right now, please try again later!
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Suspense fallback={<p>Loading config form...</p>}>
|
<Suspense fallback={<p>Loading config form...</p>}>
|
||||||
<ConfigForm values={config} setInstallationData={setInstallationData} />
|
<ConfigForm values={config} setInstallationData={setInstallationData} />
|
||||||
</Suspense>
|
</Suspense>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,26 @@
|
|||||||
import { Suspense, lazy, useEffect, useState } from "react";
|
import { Suspense, lazy, useEffect, useState } from "react"
|
||||||
import { useScript } from "usehooks-ts";
|
import { useScript } from "usehooks-ts"
|
||||||
import useApp from "~/hooks/useApp";
|
import useApp from "~/hooks/useApp"
|
||||||
|
|
||||||
import Disclaimer from "~/components/Disclaimer";
|
import Disclaimer from "~/components/Disclaimer"
|
||||||
import InvalidConfig from "~/components/InvalidConfig";
|
import InvalidConfig from "~/components/InvalidConfig"
|
||||||
|
|
||||||
import { isImageVaultDAMConfig } from "~/utils/imagevault";
|
import { isImageVaultDAMConfig } from "~/utils/imagevault"
|
||||||
import type { InsertResponse } from "~/types/imagevault";
|
import type { InsertResponse } from "~/types/imagevault"
|
||||||
|
|
||||||
const ImageVaultDAM = lazy(() => import("~/components/ImageVaultDAM"));
|
const ImageVaultDAM = lazy(() => import("~/components/ImageVaultDAM"))
|
||||||
|
|
||||||
export default function Field() {
|
export default function Field() {
|
||||||
const { sdk, config } = useApp();
|
const { sdk, config } = useApp()
|
||||||
const ivStatus = useScript(
|
const ivStatus = useScript(
|
||||||
"/scripts/imagevault-insert-media/insertmediawindow.min.js"
|
"/scripts/imagevault-insert-media/insertmediawindow.min.js"
|
||||||
);
|
)
|
||||||
|
|
||||||
const [showDisclaimer, setShowDisclaimer] = useState(false);
|
const [showDisclaimer, setShowDisclaimer] = useState(false)
|
||||||
const [fieldData, setFieldData] = useState<InsertResponse>();
|
const [fieldData, setFieldData] = useState<InsertResponse>()
|
||||||
|
|
||||||
const entry = sdk?.location.CustomField?.entry;
|
const entry = sdk?.location.CustomField?.entry
|
||||||
const field = sdk?.location.CustomField?.field;
|
const field = sdk?.location.CustomField?.field
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// If we can get field data from the SDK that means the entry has been
|
// If we can get field data from the SDK that means the entry has been
|
||||||
@@ -29,30 +29,30 @@ export default function Field() {
|
|||||||
// cannot be referred to by ImageVault. Entry title is also required by us.
|
// cannot be referred to by ImageVault. Entry title is also required by us.
|
||||||
try {
|
try {
|
||||||
if (field && entry) {
|
if (field && entry) {
|
||||||
const data = field.getData();
|
const data = field.getData()
|
||||||
const title = entry.getField("title").getData().toString();
|
const title = entry.getField("title").getData().toString()
|
||||||
if (data && title) {
|
if (data && title) {
|
||||||
setFieldData(data as InsertResponse);
|
setFieldData(data as InsertResponse)
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Missing data or title for entry");
|
throw new Error("Missing data or title for entry")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setShowDisclaimer(true);
|
setShowDisclaimer(true)
|
||||||
}
|
}
|
||||||
}, [entry, field]);
|
}, [entry, field])
|
||||||
|
|
||||||
if (showDisclaimer) {
|
if (showDisclaimer) {
|
||||||
return <Disclaimer />;
|
return <Disclaimer />
|
||||||
}
|
}
|
||||||
|
|
||||||
const loaded = !!(fieldData && ivStatus === "ready" && sdk && config);
|
const loaded = !!(fieldData && ivStatus === "ready" && sdk && config)
|
||||||
|
|
||||||
const initialData =
|
const initialData =
|
||||||
fieldData && Object.keys(fieldData).length > 0 ? fieldData : null;
|
fieldData && Object.keys(fieldData).length > 0 ? fieldData : null
|
||||||
|
|
||||||
if (!loaded) {
|
if (!loaded) {
|
||||||
return <p style={{ fontFamily: "Inter" }}> Loading dependecies...</p>;
|
return <p style={{ fontFamily: "Inter" }}> Loading dependecies...</p>
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -65,5 +65,5 @@ export default function Field() {
|
|||||||
<InvalidConfig />
|
<InvalidConfig />
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
8
remix/prettier.config.cjs
Normal file
8
remix/prettier.config.cjs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
module.exports = {
|
||||||
|
semi: false,
|
||||||
|
trailingComma: "es5",
|
||||||
|
singleQuote: false,
|
||||||
|
printWidth: 80,
|
||||||
|
tabWidth: 2,
|
||||||
|
endOfLine: "lf",
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { vitePlugin as remix } from '@remix-run/dev';
|
import { vitePlugin as remix } from "@remix-run/dev"
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from "vite"
|
||||||
import tsconfigPaths from 'vite-tsconfig-paths';
|
import tsconfigPaths from "vite-tsconfig-paths"
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [
|
plugins: [
|
||||||
@@ -12,4 +12,4 @@ export default defineConfig({
|
|||||||
build: {
|
build: {
|
||||||
emptyOutDir: true,
|
emptyOutDir: true,
|
||||||
},
|
},
|
||||||
});
|
})
|
||||||
|
|||||||
7
rte/.prettierignore
Normal file
7
rte/.prettierignore
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# Files
|
||||||
|
.eslintrc.cjs
|
||||||
|
.prettierignore
|
||||||
|
package.json
|
||||||
|
package-lock.json
|
||||||
|
prettier.config.cjs
|
||||||
|
tsconfig.json
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
import React, { PropsWithChildren } from 'react';
|
import React, { PropsWithChildren } from "react"
|
||||||
import { Tooltip } from '@contentstack/venus-components';
|
import { Tooltip } from "@contentstack/venus-components"
|
||||||
|
|
||||||
type EmbedBtnProps = PropsWithChildren & {
|
type EmbedBtnProps = PropsWithChildren & {
|
||||||
content: string;
|
content: string
|
||||||
onClick: (e: unknown) => void;
|
onClick: (e: unknown) => void
|
||||||
title: string;
|
title: string
|
||||||
};
|
}
|
||||||
|
|
||||||
export default function EmbedBtn({
|
export default function EmbedBtn({
|
||||||
content,
|
content,
|
||||||
@@ -19,13 +19,13 @@ export default function EmbedBtn({
|
|||||||
id={title}
|
id={title}
|
||||||
type="button"
|
type="button"
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e?.preventDefault();
|
e?.preventDefault()
|
||||||
e?.stopPropagation();
|
e?.stopPropagation()
|
||||||
onClick(e);
|
onClick(e)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</button>
|
</button>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useState, useEffect, ChangeEvent } from 'react';
|
import React, { useState, useEffect, ChangeEvent } from "react"
|
||||||
import {
|
import {
|
||||||
ModalFooter,
|
ModalFooter,
|
||||||
ModalBody,
|
ModalBody,
|
||||||
@@ -9,14 +9,14 @@ import {
|
|||||||
FieldLabel,
|
FieldLabel,
|
||||||
TextInput,
|
TextInput,
|
||||||
Select,
|
Select,
|
||||||
} from '@contentstack/venus-components';
|
} from "@contentstack/venus-components"
|
||||||
import { Path } from 'slate';
|
import { Path } from "slate"
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
IRteParam,
|
IRteParam,
|
||||||
IRteElementType,
|
IRteElementType,
|
||||||
} from '@contentstack/app-sdk/dist/src/RTE/types';
|
} from "@contentstack/app-sdk/dist/src/RTE/types"
|
||||||
import type { InsertResponse } from "~/types/imagevault";
|
import type { InsertResponse } from "~/types/imagevault"
|
||||||
|
|
||||||
enum DropdownValues {
|
enum DropdownValues {
|
||||||
center = "center",
|
center = "center",
|
||||||
@@ -26,10 +26,10 @@ enum DropdownValues {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type DropDownItem = {
|
type DropDownItem = {
|
||||||
label: string;
|
label: string
|
||||||
value: DropdownValues;
|
value: DropdownValues
|
||||||
type: string;
|
type: string
|
||||||
};
|
}
|
||||||
|
|
||||||
const dropdownList: DropDownItem[] = [
|
const dropdownList: DropDownItem[] = [
|
||||||
{
|
{
|
||||||
@@ -52,16 +52,16 @@ const dropdownList: DropDownItem[] = [
|
|||||||
value: DropdownValues.right,
|
value: DropdownValues.right,
|
||||||
type: "select",
|
type: "select",
|
||||||
},
|
},
|
||||||
];
|
]
|
||||||
|
|
||||||
type ImageEditModalProps = {
|
type ImageEditModalProps = {
|
||||||
element: IRteElementType & {
|
element: IRteElementType & {
|
||||||
attrs: InsertResponse;
|
attrs: InsertResponse
|
||||||
};
|
}
|
||||||
rte: IRteParam;
|
rte: IRteParam
|
||||||
closeModal: () => void;
|
closeModal: () => void
|
||||||
path: Path;
|
path: Path
|
||||||
};
|
}
|
||||||
|
|
||||||
export default function ImageEditModal({
|
export default function ImageEditModal({
|
||||||
element,
|
element,
|
||||||
@@ -73,29 +73,29 @@ export default function ImageEditModal({
|
|||||||
label: "None",
|
label: "None",
|
||||||
value: DropdownValues.none,
|
value: DropdownValues.none,
|
||||||
type: "select",
|
type: "select",
|
||||||
});
|
})
|
||||||
const [altText, setAltText] = useState("");
|
const [altText, setAltText] = useState("")
|
||||||
const [caption, setCaption] = useState("");
|
const [caption, setCaption] = useState("")
|
||||||
|
|
||||||
const assetUrl = element.attrs.MediaConversions[0].Url;
|
const assetUrl = element.attrs.MediaConversions[0].Url
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (element.attrs.Metadata && element.attrs.Metadata.length) {
|
if (element.attrs.Metadata && element.attrs.Metadata.length) {
|
||||||
const altText = element.attrs.Metadata.find((meta) =>
|
const altText = element.attrs.Metadata.find((meta) =>
|
||||||
meta.Name.includes("AltText_")
|
meta.Name.includes("AltText_")
|
||||||
)?.Value;
|
)?.Value
|
||||||
|
|
||||||
const caption = element.attrs.Metadata.find((meta) =>
|
const caption = element.attrs.Metadata.find((meta) =>
|
||||||
meta.Name.includes("Title_")
|
meta.Name.includes("Title_")
|
||||||
)?.Value;
|
)?.Value
|
||||||
|
|
||||||
setAltText(altText ?? "");
|
setAltText(altText ?? "")
|
||||||
setCaption(caption ?? "");
|
setCaption(caption ?? "")
|
||||||
}
|
}
|
||||||
}, [element.attrs.Metadata]);
|
}, [element.attrs.Metadata])
|
||||||
|
|
||||||
function handleSave() {
|
function handleSave() {
|
||||||
let newStyle;
|
let newStyle
|
||||||
|
|
||||||
switch (alignment.value) {
|
switch (alignment.value) {
|
||||||
case DropdownValues.center:
|
case DropdownValues.center:
|
||||||
@@ -106,25 +106,25 @@ export default function ImageEditModal({
|
|||||||
maxWidth: element.attrs.width
|
maxWidth: element.attrs.width
|
||||||
? `${element.attrs.width}px`
|
? `${element.attrs.width}px`
|
||||||
: undefined,
|
: undefined,
|
||||||
};
|
}
|
||||||
break;
|
break
|
||||||
case DropdownValues.none:
|
case DropdownValues.none:
|
||||||
default:
|
default:
|
||||||
newStyle = {};
|
newStyle = {}
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
const metaData = element.attrs.Metadata ?? [];
|
const metaData = element.attrs.Metadata ?? []
|
||||||
|
|
||||||
const newMetadata = metaData.map((meta) => {
|
const newMetadata = metaData.map((meta) => {
|
||||||
if (meta.Name.includes("AltText_")) {
|
if (meta.Name.includes("AltText_")) {
|
||||||
return { ...meta, Value: altText };
|
return { ...meta, Value: altText }
|
||||||
}
|
}
|
||||||
if (meta.Name.includes("Title_")) {
|
if (meta.Name.includes("Title_")) {
|
||||||
return { ...meta, Value: caption };
|
return { ...meta, Value: caption }
|
||||||
}
|
}
|
||||||
return meta;
|
return meta
|
||||||
});
|
})
|
||||||
|
|
||||||
rte._adv.Transforms?.setNodes<IRteElementType>(
|
rte._adv.Transforms?.setNodes<IRteElementType>(
|
||||||
rte._adv.editor,
|
rte._adv.editor,
|
||||||
@@ -137,9 +137,9 @@ export default function ImageEditModal({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ at: path }
|
{ at: path }
|
||||||
);
|
)
|
||||||
|
|
||||||
closeModal();
|
closeModal()
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -168,7 +168,7 @@ export default function ImageEditModal({
|
|||||||
selectLabel="Alignment"
|
selectLabel="Alignment"
|
||||||
value={alignment}
|
value={alignment}
|
||||||
onChange={(e: DropDownItem) => {
|
onChange={(e: DropDownItem) => {
|
||||||
setAlignment(e);
|
setAlignment(e)
|
||||||
}}
|
}}
|
||||||
options={dropdownList}
|
options={dropdownList}
|
||||||
/>
|
/>
|
||||||
@@ -209,5 +209,5 @@ export default function ImageEditModal({
|
|||||||
</ButtonGroup>
|
</ButtonGroup>
|
||||||
</ModalFooter>
|
</ModalFooter>
|
||||||
</>
|
</>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,27 @@
|
|||||||
import React, { useRef, useCallback, PropsWithChildren } from 'react';
|
import React, { useRef, useCallback, PropsWithChildren } from "react"
|
||||||
import { Tooltip, Icon, cbModal } from '@contentstack/venus-components';
|
import { Tooltip, Icon, cbModal } from "@contentstack/venus-components"
|
||||||
|
|
||||||
import { Resizable } from 're-resizable';
|
import { Resizable } from "re-resizable"
|
||||||
import EmbedBtn from './EmbedBtn';
|
import EmbedBtn from "./EmbedBtn"
|
||||||
import ImageEditModal from './ImageEditModal';
|
import ImageEditModal from "./ImageEditModal"
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
IRteParam,
|
IRteParam,
|
||||||
IRteElementType,
|
IRteElementType,
|
||||||
} from '@contentstack/app-sdk/dist/src/RTE/types';
|
} from "@contentstack/app-sdk/dist/src/RTE/types"
|
||||||
import type { InsertResponse } from '~/types/imagevault';
|
import type { InsertResponse } from "~/types/imagevault"
|
||||||
|
|
||||||
type ImageElementProps = PropsWithChildren & {
|
type ImageElementProps = PropsWithChildren & {
|
||||||
element: IRteElementType & { attrs: InsertResponse };
|
element: IRteElementType & { attrs: InsertResponse }
|
||||||
rte: IRteParam;
|
rte: IRteParam
|
||||||
};
|
}
|
||||||
export function ImageElement({ children, element, rte }: ImageElementProps) {
|
export function ImageElement({ children, element, rte }: ImageElementProps) {
|
||||||
const assetUrl = element.attrs.MediaConversions[0].Url;
|
const assetUrl = element.attrs.MediaConversions[0].Url
|
||||||
const isSelected = rte?.selection?.isSelected();
|
const isSelected = rte?.selection?.isSelected()
|
||||||
const isFocused = rte?.selection?.isFocused();
|
const isFocused = rte?.selection?.isFocused()
|
||||||
const isHighlight = isFocused && isSelected;
|
const isHighlight = isFocused && isSelected
|
||||||
|
|
||||||
const imgRef = useRef<HTMLDivElement | null>(null);
|
const imgRef = useRef<HTMLDivElement | null>(null)
|
||||||
|
|
||||||
const handleEdit = useCallback(() => {
|
const handleEdit = useCallback(() => {
|
||||||
cbModal({
|
cbModal({
|
||||||
@@ -36,8 +36,8 @@ export function ImageElement({ children, element, rte }: ImageElementProps) {
|
|||||||
modalProps: {
|
modalProps: {
|
||||||
size: "max",
|
size: "max",
|
||||||
},
|
},
|
||||||
});
|
})
|
||||||
}, [element, rte]);
|
}, [element, rte])
|
||||||
|
|
||||||
const ToolTipButtons = () => {
|
const ToolTipButtons = () => {
|
||||||
return (
|
return (
|
||||||
@@ -54,12 +54,12 @@ export function ImageElement({ children, element, rte }: ImageElementProps) {
|
|||||||
<Icon icon="Trash" />
|
<Icon icon="Trash" />
|
||||||
</EmbedBtn>
|
</EmbedBtn>
|
||||||
</div>
|
</div>
|
||||||
);
|
)
|
||||||
};
|
}
|
||||||
|
|
||||||
const onResizeStop = () => {
|
const onResizeStop = () => {
|
||||||
const { attrs: elementAttrs } = element;
|
const { attrs: elementAttrs } = element
|
||||||
const { offsetWidth: width, offsetHeight: height } = imgRef?.current ?? {};
|
const { offsetWidth: width, offsetHeight: height } = imgRef?.current ?? {}
|
||||||
|
|
||||||
const newAttrs: { [key: string]: unknown } = {
|
const newAttrs: { [key: string]: unknown } = {
|
||||||
...elementAttrs,
|
...elementAttrs,
|
||||||
@@ -70,24 +70,24 @@ export function ImageElement({ children, element, rte }: ImageElementProps) {
|
|||||||
...(width && height
|
...(width && height
|
||||||
? { width: `${width.toString()}px`, height: `${height.toString()}px` }
|
? { width: `${width.toString()}px`, height: `${height.toString()}px` }
|
||||||
: {}),
|
: {}),
|
||||||
};
|
}
|
||||||
|
|
||||||
rte?._adv?.Transforms?.setNodes<IRteElementType>(
|
rte?._adv?.Transforms?.setNodes<IRteElementType>(
|
||||||
rte._adv.editor,
|
rte._adv.editor,
|
||||||
{ attrs: newAttrs },
|
{ attrs: newAttrs },
|
||||||
{ at: rte.getPath(element) }
|
{ at: rte.getPath(element) }
|
||||||
);
|
)
|
||||||
};
|
}
|
||||||
|
|
||||||
let alignmentStyles = {};
|
let alignmentStyles = {}
|
||||||
const marginAlignment: Record<string, { [key: string]: string }> = {
|
const marginAlignment: Record<string, { [key: string]: string }> = {
|
||||||
center: { margin: "auto" },
|
center: { margin: "auto" },
|
||||||
left: { marginRight: "auto" },
|
left: { marginRight: "auto" },
|
||||||
right: { marginLeft: "auto" },
|
right: { marginLeft: "auto" },
|
||||||
};
|
}
|
||||||
|
|
||||||
if (typeof element.attrs.position === "string") {
|
if (typeof element.attrs.position === "string") {
|
||||||
alignmentStyles = marginAlignment[element.attrs.position];
|
alignmentStyles = marginAlignment[element.attrs.position]
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -137,7 +137,7 @@ export function ImageElement({ children, element, rte }: ImageElementProps) {
|
|||||||
<img
|
<img
|
||||||
src={assetUrl}
|
src={assetUrl}
|
||||||
onError={(event) => {
|
onError={(event) => {
|
||||||
event.currentTarget.src = "https://placehold.co/600x400";
|
event.currentTarget.src = "https://placehold.co/600x400"
|
||||||
}}
|
}}
|
||||||
style={{
|
style={{
|
||||||
width: "100%",
|
width: "100%",
|
||||||
@@ -169,5 +169,5 @@ export function ImageElement({ children, element, rte }: ImageElementProps) {
|
|||||||
</span>
|
</span>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</div>
|
</div>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
2
rte/env.d.ts
vendored
2
rte/env.d.ts
vendored
@@ -1 +1 @@
|
|||||||
declare const IS_DEV: boolean;
|
declare const IS_DEV: boolean
|
||||||
|
|||||||
134
rte/main.tsx
134
rte/main.tsx
@@ -1,70 +1,70 @@
|
|||||||
import React from 'react';
|
import React from "react"
|
||||||
import ContentstackSDK from '@contentstack/app-sdk';
|
import ContentstackSDK from "@contentstack/app-sdk"
|
||||||
|
|
||||||
import { ImageElement } from '~/components/ImageElement';
|
import { ImageElement } from "~/components/ImageElement"
|
||||||
|
|
||||||
import { Icon } from '@contentstack/venus-components';
|
import { Icon } from "@contentstack/venus-components"
|
||||||
import { openImageVault } from '~/utils/imagevault';
|
import { openImageVault } from "~/utils/imagevault"
|
||||||
|
|
||||||
import type { Lang } from '~/types/lang';
|
import type { Lang } from "~/types/lang"
|
||||||
import type {
|
import type {
|
||||||
ContentstackEmbeddedData,
|
ContentstackEmbeddedData,
|
||||||
ContentstackPluginDefinition,
|
ContentstackPluginDefinition,
|
||||||
ExtractedContentstackEmbeddedData,
|
ExtractedContentstackEmbeddedData,
|
||||||
} from '~/types/contentstack';
|
} from "~/types/contentstack"
|
||||||
|
|
||||||
function findThisPlugin(ext: ContentstackPluginDefinition) {
|
function findThisPlugin(ext: ContentstackPluginDefinition) {
|
||||||
return ext.type === 'rte_plugin' && ext.title === 'ImageVault';
|
return ext.type === "rte_plugin" && ext.title === "ImageVault"
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadScript(url: string) {
|
async function loadScript(url: string) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!document) {
|
if (!document) {
|
||||||
throw new Error('Run in browser only');
|
throw new Error("Run in browser only")
|
||||||
}
|
}
|
||||||
|
|
||||||
const head = document.head || document.getElementsByTagName('head')[0];
|
const head = document.head || document.getElementsByTagName("head")[0]
|
||||||
|
|
||||||
const script = document.createElement('script');
|
const script = document.createElement("script")
|
||||||
script.type = 'text/javascript';
|
script.type = "text/javascript"
|
||||||
script.async = true;
|
script.async = true
|
||||||
script.src = url;
|
script.src = url
|
||||||
|
|
||||||
script.onload = function () {
|
script.onload = function () {
|
||||||
this.onerror = this.onload = null;
|
this.onerror = this.onload = null
|
||||||
resolve(window.ImageVault);
|
resolve(window.ImageVault)
|
||||||
};
|
}
|
||||||
|
|
||||||
script.onerror = function () {
|
script.onerror = function () {
|
||||||
this.onerror = this.onload = null;
|
this.onerror = this.onload = null
|
||||||
reject(`Failed to load ${this.src}`);
|
reject(`Failed to load ${this.src}`)
|
||||||
};
|
}
|
||||||
|
|
||||||
head.appendChild(script);
|
head.appendChild(script)
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function extractContentstackEmbeddedData(
|
function extractContentstackEmbeddedData(
|
||||||
jwtLike: string
|
jwtLike: string
|
||||||
): ExtractedContentstackEmbeddedData | null {
|
): ExtractedContentstackEmbeddedData | null {
|
||||||
try {
|
try {
|
||||||
const base64str = jwtLike.replace(/-/g, "+").replace(/_/g, "/");
|
const base64str = jwtLike.replace(/-/g, "+").replace(/_/g, "/")
|
||||||
const jsonStr = decodeURIComponent(
|
const jsonStr = decodeURIComponent(
|
||||||
window
|
window
|
||||||
.atob(base64str)
|
.atob(base64str)
|
||||||
.split("")
|
.split("")
|
||||||
.map(function (c) {
|
.map(function (c) {
|
||||||
return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
|
return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2)
|
||||||
})
|
})
|
||||||
.join("")
|
.join("")
|
||||||
);
|
)
|
||||||
|
|
||||||
const json = JSON.parse(jsonStr);
|
const json = JSON.parse(jsonStr)
|
||||||
json.exports = JSON.parse(json.exports);
|
json.exports = JSON.parse(json.exports)
|
||||||
json.props.value = JSON.parse(json.props.value);
|
json.props.value = JSON.parse(json.props.value)
|
||||||
|
|
||||||
if (IS_DEV) {
|
if (IS_DEV) {
|
||||||
console.log(`Contentstack Embedded Data`, json);
|
console.log(`Contentstack Embedded Data`, json)
|
||||||
}
|
}
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@@ -77,12 +77,12 @@ function extractContentstackEmbeddedData(
|
|||||||
stack: { api_key },
|
stack: { api_key },
|
||||||
branch,
|
branch,
|
||||||
},
|
},
|
||||||
}: ContentstackEmbeddedData = json.props.value;
|
}: ContentstackEmbeddedData = json.props.value
|
||||||
|
|
||||||
const titleField = schema.find((f) => f.uid === "title");
|
const titleField = schema.find((f) => f.uid === "title")
|
||||||
// We force this value with ! because we know it exists.
|
// We force this value with ! because we know it exists.
|
||||||
// Otherwise this code would not run.
|
// Otherwise this code would not run.
|
||||||
const plugin = extensions.find(findThisPlugin)!;
|
const plugin = extensions.find(findThisPlugin)!
|
||||||
|
|
||||||
return {
|
return {
|
||||||
stack: {
|
stack: {
|
||||||
@@ -101,43 +101,43 @@ function extractContentstackEmbeddedData(
|
|||||||
uid: entryMetadata.entryUid,
|
uid: entryMetadata.entryUid,
|
||||||
},
|
},
|
||||||
plugin,
|
plugin,
|
||||||
};
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(`Unable to parse JWT like: ${jwtLike}`);
|
console.log(`Unable to parse JWT like: ${jwtLike}`)
|
||||||
}
|
}
|
||||||
return null;
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
let ivloaded = false;
|
let ivloaded = false
|
||||||
function loadIV(plugin: ContentstackPluginDefinition) {
|
function loadIV(plugin: ContentstackPluginDefinition) {
|
||||||
if (plugin.src) {
|
if (plugin.src) {
|
||||||
const url = new URL(plugin.src);
|
const url = new URL(plugin.src)
|
||||||
url.pathname = "/scripts/imagevault-insert-media/insertmediawindow.min.js";
|
url.pathname = "/scripts/imagevault-insert-media/insertmediawindow.min.js"
|
||||||
if (IS_DEV) {
|
if (IS_DEV) {
|
||||||
console.log(`Loading script: ${url.toString()}`);
|
console.log(`Loading script: ${url.toString()}`)
|
||||||
}
|
}
|
||||||
loadScript(url.toString());
|
loadScript(url.toString())
|
||||||
ivloaded = true;
|
ivloaded = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
try {
|
try {
|
||||||
const sdk = await ContentstackSDK.init();
|
const sdk = await ContentstackSDK.init()
|
||||||
|
|
||||||
const extensionObj = sdk?.location;
|
const extensionObj = sdk?.location
|
||||||
const RTE = extensionObj?.RTEPlugin;
|
const RTE = extensionObj?.RTEPlugin
|
||||||
|
|
||||||
let embeddedData: ExtractedContentstackEmbeddedData | null = null;
|
let embeddedData: ExtractedContentstackEmbeddedData | null = null
|
||||||
const jwtLike = window.name.split("__").find((str) => str.startsWith("ey"));
|
const jwtLike = window.name.split("__").find((str) => str.startsWith("ey"))
|
||||||
if (jwtLike) {
|
if (jwtLike) {
|
||||||
embeddedData = extractContentstackEmbeddedData(jwtLike);
|
embeddedData = extractContentstackEmbeddedData(jwtLike)
|
||||||
if (embeddedData?.plugin) {
|
if (embeddedData?.plugin) {
|
||||||
loadIV(embeddedData.plugin);
|
loadIV(embeddedData.plugin)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!RTE) return;
|
if (!RTE) return
|
||||||
|
|
||||||
const ImageVault = RTE("ImageVault", (rte) => {
|
const ImageVault = RTE("ImageVault", (rte) => {
|
||||||
if (rte) {
|
if (rte) {
|
||||||
@@ -145,11 +145,11 @@ async function init() {
|
|||||||
// Loading failed via embedded data above, try again with data inside RTE
|
// Loading failed via embedded data above, try again with data inside RTE
|
||||||
// @ts-expect-error: incorrect typings, requestProps is available at runtime
|
// @ts-expect-error: incorrect typings, requestProps is available at runtime
|
||||||
const extensions = rte._adv.editor.requestProps
|
const extensions = rte._adv.editor.requestProps
|
||||||
.extensions as ContentstackPluginDefinition[];
|
.extensions as ContentstackPluginDefinition[]
|
||||||
const plugin = extensions.find(findThisPlugin);
|
const plugin = extensions.find(findThisPlugin)
|
||||||
|
|
||||||
if (plugin) {
|
if (plugin) {
|
||||||
loadIV(plugin);
|
loadIV(plugin)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -163,35 +163,35 @@ async function init() {
|
|||||||
<ImageElement element={props.element} rte={rte}>
|
<ImageElement element={props.element} rte={rte}>
|
||||||
{props.children}
|
{props.children}
|
||||||
</ImageElement>
|
</ImageElement>
|
||||||
);
|
)
|
||||||
} else {
|
} else {
|
||||||
console.error("No instance of RTE found");
|
console.error("No instance of RTE found")
|
||||||
return (
|
return (
|
||||||
<p>An unexpected error occured, see console for more info.</p>
|
<p>An unexpected error occured, see console for more info.</p>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
display: ["toolbar"],
|
display: ["toolbar"],
|
||||||
elementType: ["void"],
|
elementType: ["void"],
|
||||||
};
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
ImageVault.on("exec", async (rte) => {
|
ImageVault.on("exec", async (rte) => {
|
||||||
if (rte) {
|
if (rte) {
|
||||||
const savedSelection = rte?.selection?.get() ?? undefined;
|
const savedSelection = rte?.selection?.get() ?? undefined
|
||||||
|
|
||||||
// @ts-expect-error: Added at runtime
|
// @ts-expect-error: Added at runtime
|
||||||
const appConfig = await rte.getConfig();
|
const appConfig = await rte.getConfig()
|
||||||
|
|
||||||
// This is the configuration for this instance of the plugin.
|
// This is the configuration for this instance of the plugin.
|
||||||
// You edit this in the content types settings RTE plugin section.
|
// You edit this in the content types settings RTE plugin section.
|
||||||
// @ts-expect-error: Added at runtime
|
// @ts-expect-error: Added at runtime
|
||||||
const pluginConfig = await rte.getFieldConfig();
|
const pluginConfig = await rte.getFieldConfig()
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
...appConfig,
|
...appConfig,
|
||||||
...pluginConfig,
|
...pluginConfig,
|
||||||
};
|
}
|
||||||
|
|
||||||
openImageVault({
|
openImageVault({
|
||||||
config,
|
config,
|
||||||
@@ -218,17 +218,17 @@ async function init() {
|
|||||||
children: [{ text: "" }],
|
children: [{ text: "" }],
|
||||||
},
|
},
|
||||||
{ at: savedSelection }
|
{ at: savedSelection }
|
||||||
);
|
)
|
||||||
},
|
},
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
return {
|
return {
|
||||||
ImageVault,
|
ImageVault,
|
||||||
};
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error({ e });
|
console.error({ e })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default init();
|
export default init()
|
||||||
|
|||||||
8
rte/prettier.config.cjs
Normal file
8
rte/prettier.config.cjs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
module.exports = {
|
||||||
|
semi: false,
|
||||||
|
trailingComma: "es5",
|
||||||
|
singleQuote: false,
|
||||||
|
printWidth: 80,
|
||||||
|
tabWidth: 2,
|
||||||
|
endOfLine: "lf",
|
||||||
|
}
|
||||||
@@ -1,28 +1,28 @@
|
|||||||
import { resolve } from 'path';
|
import { resolve } from "path"
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from "vite"
|
||||||
import tsconfigPaths from 'vite-tsconfig-paths';
|
import tsconfigPaths from "vite-tsconfig-paths"
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [tsconfigPaths()],
|
plugins: [tsconfigPaths()],
|
||||||
define: {
|
define: {
|
||||||
IS_DEV: process.env.IS_DEV === 'true' ? true : false,
|
IS_DEV: process.env.IS_DEV === "true" ? true : false,
|
||||||
},
|
},
|
||||||
publicDir: false,
|
publicDir: false,
|
||||||
build: {
|
build: {
|
||||||
sourcemap: process.env.IS_DEV ? 'inline' : 'hidden',
|
sourcemap: process.env.IS_DEV ? "inline" : "hidden",
|
||||||
emptyOutDir: true,
|
emptyOutDir: true,
|
||||||
lib: {
|
lib: {
|
||||||
entry: resolve(__dirname, 'main.tsx'),
|
entry: resolve(__dirname, "main.tsx"),
|
||||||
name: 'csiv',
|
name: "csiv",
|
||||||
fileName: () => (process.env.IS_DEV ? 'csiv.js' : 'csiv-[hash].js'),
|
fileName: () => (process.env.IS_DEV ? "csiv.js" : "csiv-[hash].js"),
|
||||||
// @ts-expect-error: 'system' not valid by typings, but works with Rollup
|
// @ts-expect-error: 'system' not valid by typings, but works with Rollup
|
||||||
formats: ['system'],
|
formats: ["system"],
|
||||||
},
|
},
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
external: ['react', 'react-dom', '@contentstack/venus-components'],
|
external: ["react", "react-dom", "@contentstack/venus-components"],
|
||||||
output: {
|
output: {
|
||||||
dir: '../remix/public/build/rte',
|
dir: "../remix/public/build/rte",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user