Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions apps/builder/app/builder/features/style-panel/shared/model.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ const getDefinedStyles = ({
];
};

const $model = computed(
export const $styleObjectModel = computed(
[
$styles,
$styleSourceSelections,
Expand Down Expand Up @@ -241,7 +241,7 @@ const $model = computed(

export const $computedStyleDeclarations = computed(
[
$model,
$styleObjectModel,
$selectedInstancePathWithRoot,
$selectedOrLastStyleSourceSelector,
$registeredComponentMetas,
Expand Down Expand Up @@ -331,7 +331,11 @@ export const $availableColorVariables = computed(

export const createComputedStyleDeclStore = (property: CssProperty) => {
return computed(
[$model, $selectedInstancePathWithRoot, $selectedOrLastStyleSourceSelector],
[
$styleObjectModel,
$selectedInstancePathWithRoot,
$selectedOrLastStyleSourceSelector,
],
(model, instancePath, styleSourceSelector) => {
return getComputedStyleDecl({
model,
Expand All @@ -345,7 +349,7 @@ export const createComputedStyleDeclStore = (property: CssProperty) => {
};

export const useStyleObjectModel = () => {
return useStore($model);
return useStore($styleObjectModel);
};

export const useComputedStyleDecl = (property: CssProperty) => {
Expand Down Expand Up @@ -378,7 +382,7 @@ export const useParentComputedStyleDecl = (property: CssProperty) => {
const $store = useMemo(
() =>
computed(
[$model, $closestStylableInstanceSelector],
[$styleObjectModel, $closestStylableInstanceSelector],
(model, instanceSelector) => {
return getComputedStyleDecl({
model,
Expand All @@ -397,7 +401,7 @@ export const getInstanceStyleDecl = (
instanceSelector: InstanceSelector
) => {
return getComputedStyleDecl({
model: $model.get(),
model: $styleObjectModel.get(),
instanceSelector,
property,
});
Expand Down
74 changes: 68 additions & 6 deletions apps/builder/app/builder/features/topbar/publish.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
startTransition,
useRef,
useId,
type ReactNode,
} from "react";
import { useStore } from "@nanostores/react";
import {
Expand Down Expand Up @@ -83,6 +84,10 @@ import { CopyToClipboard } from "~/builder/shared/copy-to-clipboard";
import { $openProjectSettings } from "~/shared/nano-states/project-settings";
import { RelativeTime } from "~/builder/shared/relative-time";
import cmsUpgradeBanner from "../settings-panel/cms-upgrade-banner.svg?url";
import { showAttribute } from "@webstudio-is/react-sdk";
import { $styleObjectModel } from "../style-panel/shared/model";
import { toValue, type CssProperty } from "@webstudio-is/css-engine";
import { getComputedStyleDecl } from "~/shared/style-object-model";

type ChangeProjectDomainProps = {
project: Project;
Expand Down Expand Up @@ -233,11 +238,11 @@ const ChangeProjectDomain = ({
};

const $usedProFeatures = computed(
[$pages, $dataSources, $instances, $propsIndex],
(pages, dataSources, instances, propsIndex) => {
[$pages, $dataSources, $instances, $propsIndex, $styleObjectModel],
(pages, dataSources, instances, propsIndex, styleObjectModel) => {
const features = new Map<
string,
undefined | { awareness?: Awareness; info?: string }
undefined | { awareness?: Awareness; info?: ReactNode }
>();
if (pages === undefined) {
return features;
Expand Down Expand Up @@ -285,7 +290,22 @@ const $usedProFeatures = computed(
const badgeFeature = 'No "Built with Webstudio" badge';
// Badge should be rendered on free sites on every page.
features.set(badgeFeature, {
info: "Adding the badge to your homepage helps us offer a free version of the service. Please open the Components panel by clicking the “+” icon on the left, and add the “Built with Webstudio” component to your page. Feel free to adjust the badge's style to match your design - after all, it's just a link, and you can place it wherever you like.",
info: (
<Text>
Adding the badge to your "home" page helps us offer a free version of
the service. Please open the Components panel by clicking the “+” icon
on the left, and add the “Built with Webstudio” component to your
page.
<br />
- Feel free to adjust the badge's style to match your design - after
all, it's just a link, and you can place it wherever you like.
<br />
- Please don’t add that badge to every page, because search engines
will view it negatively.
<br />- Hiding the link in any way is considered a violation of the
terms.
</Text>
),
});
// We want to check the badge only on the home page
const homePageInstanceIds = findTreeInstanceIds(
Expand All @@ -297,14 +317,56 @@ const $usedProFeatures = computed(
// Find a potential link that looks like a badge.
if (instance?.tag === "a") {
const props = propsIndex.propsByInstanceId.get(instance.id);
let hasWsHref = false;
let highTrust = true;
let show = true;

for (const prop of props ?? []) {
if (
prop.name === "href" &&
typeof prop.value === "string" &&
prop.type === "string" &&
prop.value.includes("https://webstudio.is")
) {
features.delete(badgeFeature);
hasWsHref = true;
}
if (prop.name === "rel" && prop.type === "string") {
if (
prop.value.includes("nofollow") ||
prop.value.includes("ugc") ||
prop.value.includes("sponsored")
) {
highTrust = false;
}
}
if (prop.name === showAttribute) {
show = prop.type === "boolean" && prop.value;
}
}

const getValue = (property: CssProperty) => {
return toValue(
getComputedStyleDecl({
model: styleObjectModel,
instanceSelector: [instance.id],
property,
}).usedValue
);
};

// Check styles.
if (
getValue("display") === "none" ||
getValue("visibility") === "hidden" ||
getValue("opacity") === "0" ||
getValue("opacity") === "0%"
) {
show = false;
}

// @todo check all parents
if (hasWsHref && highTrust && show) {
features.delete(badgeFeature);
break;
}
}
}
Expand Down