Browse Source

Merge branch 'dev' of https://github.com/GrapesJS/grapesjs into dynamic-values-improvements

dynamic-values-improvements
mohamedsalem401 10 months ago
parent
commit
454fb2b405
  1. 4
      package.json
  2. 4
      packages/cli/package.json
  3. 2
      packages/core/src/commands/index.ts
  4. 6
      packages/core/src/commands/view/ComponentDrag.ts
  5. 1
      packages/core/src/data_sources/model/conditional_variables/operators/AnyTypeOperator.ts
  6. 43
      packages/core/src/utils/Dragger.ts
  7. 1141
      pnpm-lock.yaml

4
package.json

@ -27,7 +27,7 @@
"build:docs": "pnpm --filter @grapesjs/docs build" "build:docs": "pnpm --filter @grapesjs/docs build"
}, },
"devDependencies": { "devDependencies": {
"@babel/cli": "7.24.8", "@babel/cli": "7.27.0",
"@babel/core": "7.25.2", "@babel/core": "7.25.2",
"@babel/preset-env": "7.25.4", "@babel/preset-env": "7.25.4",
"@babel/preset-typescript": "7.24.7", "@babel/preset-typescript": "7.24.7",
@ -45,7 +45,7 @@
"eslint": "8.57.0", "eslint": "8.57.0",
"eslint-config-prettier": "9.1.0", "eslint-config-prettier": "9.1.0",
"eslint-config-standard-with-typescript": "43.0.1", "eslint-config-standard-with-typescript": "43.0.1",
"eslint-plugin-import": "2.29.1", "eslint-plugin-import": "2.31.0",
"eslint-plugin-jest": "28.8.3", "eslint-plugin-jest": "28.8.3",
"eslint-plugin-n": "17.17.0", "eslint-plugin-n": "17.17.0",
"eslint-plugin-prettier": "5.2.1", "eslint-plugin-prettier": "5.2.1",

4
packages/cli/package.json

@ -36,13 +36,13 @@
"chalk": "^4.1.2", "chalk": "^4.1.2",
"core-js": "3.38.1", "core-js": "3.38.1",
"dts-bundle-generator": "^8.0.1", "dts-bundle-generator": "^8.0.1",
"html-webpack-plugin": "5.6.0", "html-webpack-plugin": "5.6.3",
"inquirer": "^8.2.5", "inquirer": "^8.2.5",
"listr": "^0.14.3", "listr": "^0.14.3",
"lodash.template": "^4.5.0", "lodash.template": "^4.5.0",
"rimraf": "^4.1.2", "rimraf": "^4.1.2",
"spdx-license-list": "^6.6.0", "spdx-license-list": "^6.6.0",
"terser-webpack-plugin": "^5.3.10", "terser-webpack-plugin": "^5.3.14",
"webpack": "5.94.0", "webpack": "5.94.0",
"webpack-cli": "5.1.4", "webpack-cli": "5.1.4",
"webpack-dev-server": "5.1.0", "webpack-dev-server": "5.1.0",

2
packages/core/src/commands/index.ts

@ -176,7 +176,7 @@ export default class CommandsModule extends Module<CommandsConfig & { pStylePref
}); });
} else { } else {
if (nativeDrag) { if (nativeDrag) {
event.dataTransfer.setDragImage(target.view?.el, 0, 0); event?.dataTransfer?.setDragImage(target.view?.el, 0, 0);
//sel.set('status', 'freezed'); //sel.set('status', 'freezed');
} }

6
packages/core/src/commands/view/ComponentDrag.ts

@ -71,6 +71,7 @@ export default {
guidesTarget: this.guidesTarget, guidesTarget: this.guidesTarget,
guidesStatic: this.guidesStatic, guidesStatic: this.guidesStatic,
guidesMatched: this.getGuidesMatched(guidesActive), guidesMatched: this.getGuidesMatched(guidesActive),
opts: this.opts,
}; };
}, },
@ -654,6 +655,11 @@ export interface ComponentDragEventProps {
* The guides that are being matched. * The guides that are being matched.
*/ */
guidesMatched: ComponentDragGuideMatched[]; guidesMatched: ComponentDragGuideMatched[];
/**
* The options used for the drag event.
*/
opts: ComponentDragOpts;
} }
/** /**

1
packages/core/src/data_sources/model/conditional_variables/operators/AnyTypeOperator.ts

@ -1,4 +1,3 @@
import { enumToArray } from '../../../utils';
import DataVariable from '../../DataVariable'; import DataVariable from '../../DataVariable';
import { SimpleOperator } from './BaseOperator'; import { SimpleOperator } from './BaseOperator';

43
packages/core/src/utils/Dragger.ts

@ -82,6 +82,12 @@ export interface DraggerOptions {
*/ */
snapOffset?: number; snapOffset?: number;
/**
* Snapping value for the x-y axis. If you pass a value of 0, the snapping will be disabled for that axis.
* @example { snapGuides: { x: 10, y: 5 } }
*/
snapGuides?: { x?: number; y?: number };
/** /**
* Document on which listen to pointer events. * Document on which listen to pointer events.
*/ */
@ -122,6 +128,7 @@ export default class Dragger {
*/ */
constructor(opts: DraggerOptions = {}) { constructor(opts: DraggerOptions = {}) {
this.opts = { this.opts = {
snapGuides: { x: 5, y: 5 },
snapOffset: 5, snapOffset: 5,
scale: 1, scale: 1,
}; };
@ -252,7 +259,7 @@ export default class Dragger {
* Check if the delta hits some guide * Check if the delta hits some guide
*/ */
snapGuides(delta: DraggerPosition) { snapGuides(delta: DraggerPosition) {
const newDelta = delta; const newDelta = { ...delta };
let { trgX, trgY } = this; let { trgX, trgY } = this;
this.guidesTarget.forEach((trg) => { this.guidesTarget.forEach((trg) => {
@ -263,13 +270,13 @@ export default class Dragger {
this.guidesStatic.forEach((stat) => { this.guidesStatic.forEach((stat) => {
if ((trg.y && stat.x) || (trg.x && stat.y)) return; if ((trg.y && stat.x) || (trg.x && stat.y)) return;
const isY = trg.y && stat.y; const isY = trg.y && stat.y;
const axs = isY ? 'y' : 'x'; const axis = isY ? 'y' : 'x';
const trgPoint = trg[axs]; const trgPoint = trg[axis];
const statPoint = stat[axs]; const statPoint = stat[axis];
const deltaPoint = delta[axs]; const deltaPoint = delta[axis];
const trgGuide = isY ? trgY : trgX; const trgGuide = isY ? trgY : trgX;
if (this.isPointIn(trgPoint, statPoint)) { if (this.isPointIn(trgPoint, statPoint, { axis })) {
if (isUndefined(trgGuide)) { if (isUndefined(trgGuide)) {
const trgValue = deltaPoint - (trgPoint - statPoint); const trgValue = deltaPoint - (trgPoint - statPoint);
this.setGuideLock(trg, trgValue); this.setGuideLock(trg, trgValue);
@ -281,18 +288,18 @@ export default class Dragger {
trgX = this.trgX; trgX = this.trgX;
trgY = this.trgY; trgY = this.trgY;
xyArr.forEach((co) => { xyArr.forEach((axis) => {
const axis = co.toUpperCase(); const axisName = axis.toUpperCase();
// @ts-ignore // @ts-ignore
let trg = this[`trg${axis}`]; let trg = this[`trg${axisName}`];
if (trg && !this.isPointIn(delta[co], trg.lock)) { if (trg && !this.isPointIn(delta[axis], trg.lock, { axis })) {
this.setGuideLock(trg, null); this.setGuideLock(trg, null);
trg = null; trg = null;
} }
if (trg && !isUndefined(trg.lock)) { if (trg && !isUndefined(trg.lock)) {
newDelta[co] = trg.lock; newDelta[axis] = trg.lock;
} }
}); });
@ -303,9 +310,17 @@ export default class Dragger {
}; };
} }
isPointIn(src: number, trg: number, { offset }: { offset?: number } = {}) { isPointIn(src: number, trg: number, { offset, axis }: { offset?: number; axis?: PositionXY } = {}) {
const ofst = offset || this.opts.snapOffset || 0; const { snapGuides = {}, snapOffset = 0 } = this.opts;
return (src >= trg && src <= trg + ofst) || (src <= trg && src >= trg - ofst); const axisOffset = axis === 'x' ? snapGuides.x : axis === 'y' ? snapGuides.y : undefined;
// If snapGuides.x or snapGuides.y is explicitly 0, disable snapping for that axis
const effectiveOffset = axisOffset === 0 ? 0 : (offset ?? axisOffset ?? snapOffset);
// If effectiveOffset is 0, snapping is disabled for this axis
if (effectiveOffset === 0) return false;
return (src >= trg && src <= trg + effectiveOffset) || (src <= trg && src >= trg - effectiveOffset);
} }
setGuideLock(guide: Guide, value: any) { setGuideLock(guide: Guide, value: any) {

1141
pnpm-lock.yaml

File diff suppressed because it is too large
Loading…
Cancel
Save