Skip to content

Commit 1eb5894

Browse files
authored
Merge pull request #294 from contentstack/VE-3972-fix-psuedo-editable-position-updates
fix: psuedo editable re-positioning logic
2 parents 5ffee44 + c6c354b commit 1eb5894

9 files changed

Lines changed: 161 additions & 116 deletions

File tree

.github/workflows/npm-publish.yml

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,22 @@
1-
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2-
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
3-
4-
name: Node.js Package
5-
1+
name: Publish Package to npmjs
62
on:
73
release:
84
types: [created]
9-
105
jobs:
116
build:
127
runs-on: ubuntu-latest
8+
permissions:
9+
contents: read
10+
id-token: write
1311
steps:
14-
- uses: actions/checkout@v2
15-
- uses: actions/setup-node@v2
12+
- uses: actions/checkout@v4
13+
# Setup .npmrc file to publish to npm
14+
- uses: actions/setup-node@v4
1615
with:
17-
node-version: 16
16+
node-version: "18"
17+
registry-url: "https://registry.npmjs.org"
1818
- run: npm ci
19-
- run: npm test
20-
21-
publish-npm:
22-
needs: build
23-
runs-on: ubuntu-latest
24-
steps:
25-
- uses: actions/checkout@v2
26-
- uses: actions/setup-node@v2
27-
with:
28-
node-version: 16
29-
registry-url: https://registry.npmjs.org/
30-
- run: npm ci
31-
- run: npm publish
19+
- run: npm run build
20+
- run: npm publish --provenance --access public
3221
env:
33-
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
22+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
],
2525
"sideEffects": false,
2626
"scripts": {
27-
"build": "tsup",
27+
"build": "NODE_OPTIONS='--max-old-space-size=16384' tsup",
2828
"test": "vitest",
2929
"test:once": "vitest run",
3030
"test:coverage": "vitest --coverage",
3131
"dev": "tsup --watch",
32-
"prepare": "npm run build && husky install",
32+
"prepare": "husky install",
3333
"lint": "eslint src",
3434
"lint:fix": "eslint --fix",
3535
"prettier": "prettier src --check",
@@ -69,6 +69,7 @@
6969
"prettier-eslint": "^15.0.1",
7070
"ssri": "^11.0.0",
7171
"ts-node": "^10.9.2",
72+
"tsc": "^2.0.4",
7273
"tsup": "^8.0.1",
7374
"tsx": "^4.19.1",
7475
"typedoc": "^0.25.13",

src/visualBuilder/components/pseudoEditableField.tsx

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import classNames from "classnames";
2-
import getCamelCaseStyles from "../utils/getCamelCaseStyles";
3-
import getStyleOfAnElement from "../utils/getStyleOfAnElement";
42
import React from "preact/compat";
53
import { visualBuilderStyles } from "../visualBuilder.style";
4+
import { getPsuedoEditableElementStyles } from "../utils/getPsuedoEditableStylesElement";
65

76
interface PseudoEditableFieldProps {
87
editableElement: HTMLElement;
@@ -12,27 +11,14 @@ interface PseudoEditableFieldProps {
1211
function PseudoEditableFieldComponent(
1312
props: PseudoEditableFieldProps
1413
): JSX.Element {
15-
const styles = getCamelCaseStyles(
16-
getStyleOfAnElement(props.editableElement)
17-
);
18-
// Get the offsetTop and offsetLeft of the editable element and set the position of the pseudo editable element
19-
// The pseudo editable element is positioned absolutely at the same location as the editable element
20-
const rect = props.editableElement.getBoundingClientRect();
21-
22-
styles.position = "absolute";
23-
styles.top = `${rect.top + window.scrollY}px`;
24-
styles.left = `${rect.left + window.scrollX}px`;
25-
// setting height to auto so that the element can grow based on the content
26-
// and the resize observer can detect the change in height
27-
styles.height = "auto";
28-
styles.whiteSpace = "pre-line"
29-
styles.textTransform = "none"
14+
const styles = getPsuedoEditableElementStyles(props.editableElement, true);
3015

3116
return (
3217
<div
33-
className={
34-
classNames("visual-builder__pseudo-editable-element", visualBuilderStyles()["visual-builder__pseudo-editable-element"])
35-
}
18+
className={classNames(
19+
"visual-builder__pseudo-editable-element",
20+
visualBuilderStyles()["visual-builder__pseudo-editable-element"]
21+
)}
3622
data-testid="visual-builder__pseudo-editable-element"
3723
style={styles}
3824
>

src/visualBuilder/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ export class VisualBuilder {
7676
visualBuilderContainer: this.visualBuilderContainer,
7777
overlayWrapper: this.overlayWrapper,
7878
focusedToolbar: this.focusedToolbar,
79-
resizeObserver: this.resizeObserver,
8079
});
8180
}
8281

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import getCamelCaseStyles from "./getCamelCaseStyles";
2+
import getStyleOfAnElement from "./getStyleOfAnElement";
3+
4+
export function getPsuedoEditableElementStyles(
5+
psuedoEditableElement: HTMLElement,
6+
camelCase?: boolean
7+
): { [key: string]: string } {
8+
let styles = getStyleOfAnElement(psuedoEditableElement);
9+
if (camelCase) {
10+
styles = getCamelCaseStyles(styles);
11+
}
12+
// Get the offsetTop and offsetLeft of the editable element and set the position of the pseudo editable element
13+
// The pseudo editable element is positioned absolutely at the same location as the editable element
14+
const rect = psuedoEditableElement.getBoundingClientRect();
15+
16+
styles.position = "absolute";
17+
styles.top = `${rect.top + window.scrollY}px`;
18+
styles.left = `${rect.left + window.scrollX}px`;
19+
// setting height to auto so that the element can grow based on the content
20+
// and the resize observer can detect the change in height
21+
styles.height = "auto";
22+
styles.whiteSpace = "pre-line";
23+
styles.textTransform = "none";
24+
25+
return styles;
26+
}

src/visualBuilder/utils/getStyleOfAnElement.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export default function getStyleOfAnElement(element: HTMLElement): {
1717
"right",
1818
"bottom",
1919
"text-overflow",
20+
// allows seeing the text from CMS field as-is
21+
"text-transform",
2022
"margin",
2123
"margin-block-end",
2224
"margin-block-start",

src/visualBuilder/utils/handleIndividualFields.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ export async function handleIndividualFields(
200200
editableElement: actualEditableField,
201201
visualBuilderContainer,
202202
overlayWrapper,
203-
resizeObserver,
204203
focusedToolbar,
205204
});
206205
}, 200);

0 commit comments

Comments
 (0)