Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ssr Make flow SSR friendly #31

Merged
merged 1 commit into from
Sep 27, 2024
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
6 changes: 6 additions & 0 deletions packages/flow-core-config/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

# Change Log

## [1.1.7] - 2024-09-26

### Patch changes

- Make `flow-core-config` SSR friendly

## [1.1.6] - 2023-08-20

### Patch changes
Expand Down
2 changes: 1 addition & 1 deletion packages/flow-core-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nonfx/flow-core-config",
"version": "1.1.6",
"version": "1.1.7",
"description": "Shared configuration for the Flow UI library",
"module": "dist/index.es.js",
"main": "dist/index.cjs.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/flow-core-config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const ConfigUtil = {
const cssSet = new Set<string>();

export function injectCss(id: string, css: string) {
if (cssSet.has(id) || !document) {
if (cssSet.has(id) || typeof document === "undefined") {
return;
}

Expand Down
6 changes: 6 additions & 0 deletions packages/flow-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

# Change Log

## [2.10.20] - 2024-09-26

### Patch Changes

- Make `flow-core` SSR friendly

## [2.10.19] - 2024-09-26

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/flow-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nonfx/flow-core",
"version": "2.10.19",
"version": "2.10.20",
"description": "Core package of flow design system",
"module": "dist/flow-core.es.js",
"main": "dist/flow-core.cjs.js",
Expand Down Expand Up @@ -58,7 +58,7 @@
"web-component-analyzer": "^2.0.0-next.4"
},
"peerDependencies": {
"@nonfx/flow-core-config": "^1.1.4"
"@nonfx/flow-core-config": "^1.1.7"
},
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { FRoot } from "../../mixins/components/f-root/f-root";
import { flowElement } from "./../../utils";
import { injectCss } from "@nonfx/flow-core-config";

import "vanilla-colorful";
import { FPopover } from "../f-popover/f-popover";
import { FDiv } from "../f-div/f-div";
import { FInput } from "../f-input/f-input";
Expand All @@ -19,6 +18,10 @@ export type FColorPickerInputEvent = {
value?: string;
};

if (typeof document !== "undefined") {
import("vanilla-colorful");
}

@flowElement("f-color-picker")
export class FColorPicker extends FRoot {
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/flow-core/src/components/f-select/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { unsafeSVG } from "lit-html/directives/unsafe-svg.js";
import loader from "../../mixins/svg/loader";
import { map } from "lit/directives/map.js";

if (!customElements.get("lit-virtualizer")) {
if (typeof document !== "undefined" && !customElements.get("lit-virtualizer")) {
import("@lit-labs/virtualizer").catch(err => {
console.error("Failed to load lit-virtualizer:", err);
});
Expand Down
34 changes: 18 additions & 16 deletions packages/flow-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,28 @@ export * from "./components/f-countdown/f-countdown";

export { html } from "lit";

if (document.readyState !== "loading") {
ConfigUtil.initTheme();
} else {
document.addEventListener("DOMContentLoaded", function () {
if (typeof document !== "undefined") {
if (document.readyState !== "loading") {
ConfigUtil.initTheme();
});
}
} else {
document.addEventListener("DOMContentLoaded", function () {
ConfigUtil.initTheme();
});
}

document.addEventListener("keyup", (event: KeyboardEvent) => {
event.preventDefault();
document.addEventListener("keyup", (event: KeyboardEvent) => {
event.preventDefault();

if (event.key && event.key.toLowerCase() === "x" && event.shiftKey && event.ctrlKey) {
// console.log("Changing theme");
const currentTheme = ConfigUtil.getConfig().theme;
if (event.key && event.key.toLowerCase() === "x" && event.shiftKey && event.ctrlKey) {
// console.log("Changing theme");
const currentTheme = ConfigUtil.getConfig().theme;

ConfigUtil.setConfig({
theme: currentTheme === "f-dark" ? "f-light" : "f-dark"
});
}
});
ConfigUtil.setConfig({
theme: currentTheme === "f-dark" ? "f-light" : "f-dark"
});
}
});
}

console.log(
`%c@nonfx/flow-core%cv${version}`,
Expand Down
Loading