juo 0.3.0-alpha.0 → 0.3.0-alpha.2

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.
Files changed (34) hide show
  1. package/README.md +1 -1
  2. package/bin/dev.js +15 -4
  3. package/dist/commands/blocks/dev.d.ts +2 -2
  4. package/dist/commands/create.d.ts +4 -4
  5. package/dist/commands/create.js +85 -38
  6. package/dist/commands/generate.d.ts +5 -5
  7. package/dist/commands/publish/index.d.ts +2 -2
  8. package/dist/lib/index.d.ts +2 -0
  9. package/dist/lib/index.js +1 -1
  10. package/dist/{packageGenerator-Bx2FAq2Y.js → packageGenerator-BToocy-h.js} +6 -7
  11. package/oclif.manifest.json +1 -1
  12. package/package.json +1 -1
  13. package/templates/.storybook/preview-head.html.liquid +3 -5
  14. package/templates/block/preact/index.ts.liquid +65 -10
  15. package/templates/block/preact/{{block.clsName}}.tsx.liquid +100 -130
  16. package/templates/block/react/index.ts.liquid +64 -8
  17. package/templates/block/react/{{block.clsName}}.tsx.liquid +109 -61
  18. package/templates/configFiles/src/main.ts.liquid +5 -0
  19. package/templates/configFiles/vite-env.d.ts.liquid +11 -1
  20. package/templates/configFiles/vite.config.ts.liquid +1 -1
  21. package/templates/css/styles.css +31 -35
  22. package/templates/dev/index.html.liquid +18 -2
  23. package/templates/dev/vite/blocks-shim.ts.liquid +6 -0
  24. package/templates/dev/vite/juo-editor-plugin.ts.liquid +23 -2
  25. package/templates/dev/vite/mock-login.ts.liquid +83 -0
  26. package/templates/dev/vite/mock-services.ts.liquid +140 -0
  27. package/templates/dev/vite/theme-shell.ts.liquid +267 -0
  28. package/templates/dev/vite/workflowOverlay.ts.liquid +280 -0
  29. package/templates/stories/{{block.clsName}}.stories.tsx.liquid +6 -3
  30. package/templates/tailwind/postcss.config.js.liquid +6 -0
  31. package/templates/tailwind/src/tailwind.css.liquid +4 -2
  32. package/templates/tailwind/tailwind.config.cjs.liquid +15 -0
  33. package/templates/dev/src/main.ts.liquid +0 -136
  34. package/templates/tailwind/vite.config.ts.liquid +0 -35
@@ -1,136 +0,0 @@
1
- import "@juo/blocks/web-components/editor";
2
- {% if tailwind %}import "./tailwind.css";
3
- {% else %}import "./styles.css";
4
- {% endif %}
5
- import {
6
- createBlockInstance,
7
- createThemeState,
8
- defineBlock,
9
- effect,
10
- injectContext,
11
- isEditorPreview,
12
- provideContext,
13
- registerBlock,
14
- serializeBlocks,
15
- ThemeStateContext,
16
- TranslationContext,
17
- createTranslationService,
18
- untracked,
19
- } from "@juo/blocks";
20
- import { registerBlocks as registerProjectBlocks } from "./blocks/register";
21
-
22
- const homePageBlock = defineBlock("HomePage", {
23
- displayName: "Home page",
24
- group: "page",
25
- schema: {
26
- type: "object",
27
- properties: {
28
- props: {
29
- type: "object",
30
- properties: {},
31
- additionalProperties: false,
32
- },
33
- slots: {
34
- type: "object",
35
- properties: { main: {} },
36
- additionalProperties: false,
37
- },
38
- },
39
- required: ["props", "slots"],
40
- additionalProperties: false,
41
- },
42
- initialValue: () => ({
43
- props: {},
44
- slots: {
45
- main: [createBlockInstance("Starter Block")],
46
- },
47
- }),
48
- renderer() {
49
- const page = document.createElement("juo-page");
50
- page.setAttribute("name", "HomePage");
51
- const extensionRoot = document.createElement("juo-extension-root");
52
- extensionRoot.setAttribute("name", "main");
53
- page.appendChild(extensionRoot);
54
- return page;
55
- },
56
- });
57
-
58
- function registerBlocks() {
59
- registerProjectBlocks();
60
- registerBlock(homePageBlock);
61
- }
62
-
63
- async function setupEditorMode(root: HTMLElement) {
64
- const editorModule = await import("@juo/blocks/editor");
65
- const editor = editorModule.createEditorBridge();
66
- const routerService = {
67
- push: () => {},
68
- subscribe: () => () => {},
69
- getPages: () => [{ path: "/", block: "HomePage", title: "Home", routeNames: [] }],
70
- };
71
- const themeState = createThemeState({
72
- resolve: (surface, path) => editor.requestThemeState(surface, path),
73
- upsertState: (surface, path, blocks) =>
74
- editor.upsertThemeState(surface, path, blocks),
75
- translations: {
76
- resolveTranslations: (locale) =>
77
- editor.requestTranslationOverrides(locale),
78
- },
79
- routerService,
80
- });
81
- provideContext(root, ThemeStateContext, themeState);
82
- await editorModule.setupEditorMode({ routerService, themeState });
83
- }
84
-
85
- function setupViewMode(root: HTMLElement) {
86
- const themeState = createThemeState({
87
- resolve: async () => ({
88
- blocks: serializeBlocks([createBlockInstance("HomePage")]),
89
- }),
90
- });
91
- provideContext(root, ThemeStateContext, themeState);
92
- }
93
-
94
- async function initializeTheme() {
95
- const root = document.querySelector("juo-context-root") as HTMLElement;
96
-
97
- registerBlocks();
98
-
99
- if (isEditorPreview()) {
100
- await setupEditorMode(root);
101
- } else {
102
- setupViewMode(root);
103
- }
104
-
105
- const themeState = injectContext(root, ThemeStateContext);
106
-
107
- await themeState.locales.setLocale("en");
108
- provideContext(
109
- root,
110
- TranslationContext,
111
- createTranslationService(themeState.locales, {
112
- async loadDefaultTranslations() {
113
- return {};
114
- },
115
- }),
116
- );
117
-
118
- void themeState.resolve("page", "/");
119
-
120
- effect(() => {
121
- const block = themeState.page.blocks.value.at(0);
122
- untracked(() => {
123
- if (block == null) {
124
- document.querySelector("#app")?.replaceChildren();
125
- } else {
126
- document.querySelector("#app")?.replaceChildren(block.definition.render(block));
127
- }
128
- });
129
- });
130
- }
131
-
132
- if (document.readyState === "loading") {
133
- document.addEventListener("DOMContentLoaded", () => void initializeTheme());
134
- } else {
135
- void initializeTheme();
136
- }
@@ -1,35 +0,0 @@
1
- import { defineConfig } from "vite";
2
- import tailwindcss from "@tailwindcss/vite";
3
- import svgr from "vite-plugin-svgr";
4
- import juo from "./vite/juo-editor-plugin";
5
- {% if framework == "react" %}
6
- import react from "@vitejs/plugin-react";
7
- {% elsif framework == "preact" %}
8
- import preact from "@preact/preset-vite";
9
- {% endif %}
10
-
11
- export default defineConfig({
12
- define: {
13
- "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
14
- },
15
- plugins: [tailwindcss(), juo(){% if framework == "react" %}, react(){% endif %}{% if framework == "preact" %}, preact(){% endif %},
16
- svgr({
17
- svgrOptions: {
18
- icon: true,
19
- },
20
- }),
21
- ],
22
- preview: {
23
- cors: true,
24
- },
25
- build: {
26
- lib: {
27
- entry: "src/blocks/register.ts",
28
- formats: ["es"],
29
- fileName: "index",
30
- },
31
- rollupOptions: {
32
- external: [/^@juo\/blocks/],
33
- },
34
- },
35
- });