Skip to content

Commit e622e08

Browse files
authored
refactor: drop legacy matchers (#5146)
We already fully switched to component content model and no longer necessary legacy matchers.
1 parent 618f70b commit e622e08

File tree

10 files changed

+42
-1243
lines changed

10 files changed

+42
-1243
lines changed

apps/builder/app/builder/features/ai/apply-operations.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { nanoid } from "nanoid";
2-
import { getStyleDeclKey, Instance, type StyleSource } from "@webstudio-is/sdk";
2+
import {
3+
getStyleDeclKey,
4+
Instance,
5+
isComponentDetachable,
6+
type StyleSource,
7+
} from "@webstudio-is/sdk";
38
import { generateDataFromEmbedTemplate } from "@webstudio-is/react-sdk";
49
import type { copywriter, operations } from "@webstudio-is/ai";
510
import { serverSyncStore } from "~/shared/sync";
@@ -23,7 +28,6 @@ import {
2328
} from "~/shared/nano-states";
2429
import type { InstanceSelector } from "~/shared/tree-utils";
2530
import { $selectedInstance, getInstancePath } from "~/shared/awareness";
26-
import { isInstanceDetachable } from "~/shared/matcher";
2731
import { isRichTextTree } from "~/shared/content-model";
2832

2933
export const applyOperations = (operations: operations.WsOperations) => {
@@ -91,15 +95,10 @@ const deleteInstanceByOp = (
9195
if (instanceSelector.length === 1) {
9296
return;
9397
}
94-
const metas = $registeredComponentMetas.get();
9598
updateWebstudioData((data) => {
96-
if (
97-
isInstanceDetachable({
98-
metas,
99-
instances: data.instances,
100-
instanceSelector,
101-
}) === false
102-
) {
99+
const [instanceId] = instanceSelector;
100+
const instance = data.instances.get(instanceId);
101+
if (instance && !isComponentDetachable(instance.component)) {
103102
return;
104103
}
105104
deleteInstanceMutable(

apps/builder/app/builder/features/navigator/navigator-tree.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ import {
6666
getInstanceKey,
6767
selectInstance,
6868
} from "~/shared/awareness";
69-
import { isTreeMatching } from "~/shared/matcher";
7069
import {
7170
findClosestContainer,
7271
isRichTextContent,
@@ -562,12 +561,7 @@ const canDrop = (
562561
}
563562
// make sure dragging tree can be put inside of drop instance
564563
const containerInstanceSelector = [dragSelector[0], ...dropSelector];
565-
let matches = isTreeMatching({
566-
instances,
567-
metas,
568-
instanceSelector: containerInstanceSelector,
569-
});
570-
matches &&= isTreeSatisfyingContentModel({
564+
const matches = isTreeSatisfyingContentModel({
571565
instances,
572566
metas,
573567
props,

apps/builder/app/builder/shared/commands.ts

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { nanoid } from "nanoid";
2-
import { blockTemplateComponent } from "@webstudio-is/sdk";
2+
import {
3+
blockTemplateComponent,
4+
isComponentDetachable,
5+
} from "@webstudio-is/sdk";
36
import type { Instance } from "@webstudio-is/sdk";
47
import { toast } from "@webstudio-is/design-system";
58
import { createCommandsEmitter, type Command } from "~/shared/commands-emitter";
@@ -36,7 +39,6 @@ import {
3639
import { $selectedInstancePath, selectInstance } from "~/shared/awareness";
3740
import { openCommandPanel } from "../features/command-panel";
3841
import { builderApi } from "~/shared/builder-api";
39-
import { isInstanceDetachable, isTreeMatching } from "~/shared/matcher";
4042
import { getSetting, setSetting } from "./client-settings";
4143
import { findAvailableVariables } from "~/shared/data-variables";
4244
import { atom } from "nanostores";
@@ -77,14 +79,7 @@ export const deleteSelectedInstance = () => {
7779
const [selectedItem, parentItem] = instancePath;
7880
const selectedInstanceSelector = selectedItem.instanceSelector;
7981
const instances = $instances.get();
80-
const metas = $registeredComponentMetas.get();
81-
if (
82-
isInstanceDetachable({
83-
metas,
84-
instances,
85-
instanceSelector: selectedInstanceSelector,
86-
}) === false
87-
) {
82+
if (!isComponentDetachable(selectedItem.instance.component)) {
8883
toast.error(
8984
"This instance can not be moved outside of its parent component."
9085
);
@@ -110,12 +105,12 @@ export const deleteSelectedInstance = () => {
110105
blockTemplateComponent;
111106

112107
if (isTemplateInstance) {
113-
builderApi.toast.info("You can't delete this instance in conent mode.");
108+
builderApi.toast.info("You can't delete this instance in content mode.");
114109
return;
115110
}
116111

117112
if (!isChildOfBlock) {
118-
builderApi.toast.info("You can't delete this instance in conent mode.");
113+
builderApi.toast.info("You can't delete this instance in content mode.");
119114
return;
120115
}
121116
}
@@ -180,12 +175,7 @@ export const wrapIn = (component: string) => {
180175
}
181176
}
182177
}
183-
let matches = isTreeMatching({
184-
metas,
185-
instances: data.instances,
186-
instanceSelector: newInstanceSelector,
187-
});
188-
matches &&= isTreeSatisfyingContentModel({
178+
const matches = isTreeSatisfyingContentModel({
189179
instances: data.instances,
190180
props: data.props,
191181
metas,
@@ -231,12 +221,7 @@ export const unwrap = () => {
231221
);
232222
parentInstance.children.splice(index, 1, ...selectedInstance.children);
233223
}
234-
let matches = isTreeMatching({
235-
metas: $registeredComponentMetas.get(),
236-
instances: data.instances,
237-
instanceSelector: parentItem.instanceSelector,
238-
});
239-
matches &&= isTreeSatisfyingContentModel({
224+
const matches = isTreeSatisfyingContentModel({
240225
instances: data.instances,
241226
props: data.props,
242227
metas: $registeredComponentMetas.get(),

apps/builder/app/canvas/shared/use-drag-drop.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ import {
2929
type InstanceSelector,
3030
areInstanceSelectorsEqual,
3131
} from "~/shared/tree-utils";
32-
import {
33-
findClosestInstanceMatchingFragment,
34-
isTreeMatching,
35-
} from "~/shared/matcher";
32+
import { findClosestInstanceMatchingFragment } from "~/shared/matcher";
3633
import {
3734
findClosestContainer,
3835
findClosestRichText,
@@ -98,12 +95,7 @@ const findClosestDroppableInstanceSelector = (
9895
dragPayload.dragInstanceSelector[0],
9996
...instanceSelector,
10097
];
101-
let matches = isTreeMatching({
102-
instances,
103-
metas,
104-
instanceSelector: dropInstanceSelector,
105-
});
106-
matches &&= isTreeSatisfyingContentModel({
98+
const matches = isTreeSatisfyingContentModel({
10799
instances,
108100
props,
109101
metas,

apps/builder/app/shared/copy-paste/plugin-instance.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@ import {
66
Instances,
77
WebstudioFragment,
88
findTreeInstanceIdsExcludingSlotDescendants,
9+
isComponentDetachable,
910
portalComponent,
1011
} from "@webstudio-is/sdk";
11-
import {
12-
$selectedInstanceSelector,
13-
$instances,
14-
$registeredComponentMetas,
15-
} from "../nano-states";
12+
import { $selectedInstanceSelector, $instances } from "../nano-states";
1613
import type { InstanceSelector } from "../tree-utils";
1714
import {
1815
deleteInstanceMutable,
@@ -24,7 +21,6 @@ import {
2421
findClosestInsertable,
2522
type Insertable,
2623
} from "../instance-utils";
27-
import { isInstanceDetachable } from "../matcher";
2824
import { $selectedInstancePath } from "../awareness";
2925
import { findAvailableVariables } from "../data-variables";
3026

@@ -38,8 +34,9 @@ type InstanceData = z.infer<typeof InstanceData>;
3834

3935
const getTreeData = (instanceSelector: InstanceSelector) => {
4036
const instances = $instances.get();
41-
const metas = $registeredComponentMetas.get();
42-
if (isInstanceDetachable({ metas, instances, instanceSelector }) === false) {
37+
const [targetInstanceId] = instanceSelector;
38+
const instance = instances.get(targetInstanceId);
39+
if (instance && !isComponentDetachable(instance.component)) {
4340
toast.error(
4441
"This instance can not be moved outside of its parent component."
4542
);
@@ -51,8 +48,6 @@ const getTreeData = (instanceSelector: InstanceSelector) => {
5148
return;
5249
}
5350

54-
const [targetInstanceId] = instanceSelector;
55-
5651
return {
5752
instanceSelector,
5853
...extractWebstudioFragment(getWebstudioData(), targetInstanceId),

0 commit comments

Comments
 (0)