oc-template-preact-compiler 0.7.5 → 0.8.0
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/lib/hmr.d.ts +7 -0
- package/dist/lib/hmr.js +32 -0
- package/package.json +1 -1
- package/scaffold/src/package.json +2 -2
- package/scaffold/src/src/server.ts +25 -23
package/dist/lib/hmr.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.plugin = exports.appBlock = void 0;
|
|
7
|
+
const preset_vite_1 = __importDefault(require("@preact/preset-vite"));
|
|
8
|
+
exports.plugin = preset_vite_1.default;
|
|
9
|
+
const appBlock = ({ name, version, entry }) => `
|
|
10
|
+
<div id="root"></div>
|
|
11
|
+
<script type="module">
|
|
12
|
+
const data = __INITIAL_DATA__;
|
|
13
|
+
window.__$$oc_initialData__ = Object.freeze(data);
|
|
14
|
+
const settings = Object.freeze({ baseUrl: '/', id: 'root', name: '${name}', staticPath: '/', version: '${version}' });
|
|
15
|
+
window.__$$oc_Settings__ = settings;
|
|
16
|
+
|
|
17
|
+
window.oc = window.oc || {};
|
|
18
|
+
window.oc.cmd = window.oc.cmd || [];
|
|
19
|
+
|
|
20
|
+
import App from "${entry}";
|
|
21
|
+
import { render, createElement } from 'preact';
|
|
22
|
+
|
|
23
|
+
const app = createElement(App, data);
|
|
24
|
+
const container = document.getElementById('root');
|
|
25
|
+
|
|
26
|
+
window.oc.cmd.push(() => {
|
|
27
|
+
render(app, container);
|
|
28
|
+
window.oc.events.fire('oc:rendered', { ...settings, element: container, });
|
|
29
|
+
});
|
|
30
|
+
</script>
|
|
31
|
+
`;
|
|
32
|
+
exports.appBlock = appBlock;
|
package/package.json
CHANGED
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"@testing-library/react": "^14.0.0",
|
|
35
35
|
"@testing-library/user-event": "^14.4.3",
|
|
36
36
|
"jsdom": "^21.1.1",
|
|
37
|
-
"oc-server": "^1.1.
|
|
38
|
-
"oc-template-preact-compiler": "^0.7.
|
|
37
|
+
"oc-server": "^1.1.4",
|
|
38
|
+
"oc-template-preact-compiler": "^0.7.6",
|
|
39
39
|
"preact": "^10.13.2",
|
|
40
40
|
"typescript": "5.0.2",
|
|
41
41
|
"vitest": "^0.29.7"
|
|
@@ -19,29 +19,31 @@ async function getFunFact(year: number) {
|
|
|
19
19
|
return yearsFunFactDatabase[year];
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export const server = new Server(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
22
|
+
export const server = new Server()
|
|
23
|
+
.handler(async (params: { userId: number }) => {
|
|
24
|
+
const { userId } = params;
|
|
25
|
+
const user = await getUser(userId);
|
|
26
|
+
const [firstName, lastName] = user.name.split(/\s+/);
|
|
27
|
+
|
|
28
|
+
if (firstName === 'Invalid') {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
firstName,
|
|
34
|
+
lastName,
|
|
35
|
+
born: user.born,
|
|
36
|
+
hobbies: user.hobbies,
|
|
37
|
+
};
|
|
38
|
+
})
|
|
39
|
+
.action('funFact', async (params: { year: number }) => {
|
|
40
|
+
const { year } = params;
|
|
41
|
+
const funFact = await getFunFact(year);
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
funFact,
|
|
45
|
+
};
|
|
46
|
+
});
|
|
45
47
|
|
|
46
48
|
declare module 'oc-server' {
|
|
47
49
|
interface Register {
|