@elementor/editor-elements 4.4.0-1121 → 4.4.0-1123
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -264,6 +264,7 @@ function attachChildFromRule(parentId, rule, stash) {
|
|
|
264
264
|
const currentChildren = getDirectChildData(parent);
|
|
265
265
|
const alreadyPresent = currentChildren.some((child) => child.elType === rule.child_type);
|
|
266
266
|
if (alreadyPresent) {
|
|
267
|
+
placeAnchoredChild(parentId, rule);
|
|
267
268
|
return;
|
|
268
269
|
}
|
|
269
270
|
const { modelData, wasStashed } = resolveChildModelData(parentId, rule, stash);
|
|
@@ -293,6 +294,36 @@ function detachChildFromRule(parentId, rule, stash) {
|
|
|
293
294
|
}
|
|
294
295
|
requestNavigatorRefresh(parentId);
|
|
295
296
|
}
|
|
297
|
+
function placeAnchoredChild(parentId, rule) {
|
|
298
|
+
if (rule.position.kind !== "after_type" && rule.position.kind !== "before_type") {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
let parent;
|
|
302
|
+
try {
|
|
303
|
+
parent = getContainer(parentId) ?? void 0;
|
|
304
|
+
} catch {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
const collection = parent?.model?.get?.("elements");
|
|
308
|
+
const models = collection?.models;
|
|
309
|
+
if (!models || !collection?.remove || !collection?.add) {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
const existingIndex = models.findIndex((model2) => model2.get("elType") === rule.child_type);
|
|
313
|
+
if (existingIndex < 0) {
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
const siblings = models.map((model2) => ({ elType: model2.get("elType") }));
|
|
317
|
+
const remaining = siblings.filter((_, index) => index !== existingIndex);
|
|
318
|
+
const insertAt = resolveInsertIndex(rule.position, remaining);
|
|
319
|
+
if (insertAt === existingIndex) {
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
const model = models[existingIndex];
|
|
323
|
+
collection.remove(model, { silent: true });
|
|
324
|
+
collection.add(model, { at: insertAt, silent: true });
|
|
325
|
+
requestNavigatorRefresh(parentId);
|
|
326
|
+
}
|
|
296
327
|
function requestNavigatorRefresh(parentId) {
|
|
297
328
|
if (typeof window === "undefined" || typeof window.dispatchEvent !== "function") {
|
|
298
329
|
return;
|
|
@@ -324,6 +355,15 @@ function reconcileInitialChildren({
|
|
|
324
355
|
const isMet = evaluateWhen(rule.when, settings);
|
|
325
356
|
const existingIndex = elements.findIndex((element) => element.elType === rule.child_type);
|
|
326
357
|
const isPresent = existingIndex >= 0;
|
|
358
|
+
if (isMet && isPresent && isAnchoredPosition(rule.position.kind)) {
|
|
359
|
+
const remaining = elements.filter((_, index) => index !== existingIndex);
|
|
360
|
+
const insertAt = resolveInsertIndex(rule.position, remaining);
|
|
361
|
+
if (insertAt !== existingIndex) {
|
|
362
|
+
const [moved] = elements.splice(existingIndex, 1);
|
|
363
|
+
elements.splice(insertAt, 0, moved);
|
|
364
|
+
}
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
327
367
|
if (isMet && !isPresent) {
|
|
328
368
|
const { modelData, wasStashed } = resolveChildModelData(elementId, rule, stash);
|
|
329
369
|
const insertAt = resolveInsertIndex(rule.position, elements);
|
|
@@ -342,6 +382,9 @@ function reconcileInitialChildren({
|
|
|
342
382
|
});
|
|
343
383
|
attributes.elements = elements;
|
|
344
384
|
}
|
|
385
|
+
function isAnchoredPosition(kind) {
|
|
386
|
+
return kind === "after_type" || kind === "before_type";
|
|
387
|
+
}
|
|
345
388
|
|
|
346
389
|
// src/hooks/use-element-children.ts
|
|
347
390
|
var import_editor_v1_adapters2 = require("@elementor/editor-v1-adapters");
|