@cdlab996/lowcode-vue-core 0.0.0-stage → 2.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023, cdLab996
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,99 @@
1
- # Temporary Holding Version
1
+ # @cdlab996/lowcode-vue-core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Vue-version independent core of the LowCode Engine renderer and designer
4
+ simulator. Applications install `@cdlab996/lowcode-vue2` or
5
+ `@cdlab996/lowcode-vue3`: both depend on this package and re-export its API
6
+ with their adapter installed (importing them calls `setAdapter()`). The code
7
+ generator depends on its `./schema` entry.
8
+
9
+ Use the core directly only to share code between the two Vue versions (a
10
+ library written against the renderer API) or for the schema rules; import a
11
+ distribution first so an adapter is set.
12
+
13
+ ```bash
14
+ pnpm add @cdlab996/lowcode-vue3 # or @cdlab996/lowcode-vue2
15
+ ```
16
+
17
+ Inside the repository the package exports its TypeScript sources (tests,
18
+ type-checks and `pnpm dev` use them directly); `publishConfig` points the
19
+ published package at the tsdown build in `dist`.
20
+
21
+ ## Entries
22
+
23
+ | Entry | Content |
24
+ | ----------------- | ------------------------------------------------------------------------- |
25
+ | `.` | `./runtime` plus the designer simulator (`createSimulatorRenderer`) |
26
+ | `./runtime` | adapter, renderer context, renderer, shared helpers |
27
+ | `./schema` | how a node schema is read; shared with the code generator (no Vue import) |
28
+ | `./designer` | `setupDesignerEnvironment(project, { vue })` for the designer page |
29
+ | `./simulator.css` | canvas styles |
30
+
31
+ `vue` (`^2.7.16 || ^3.5.0`) is an optional peer dependency: `./schema` and
32
+ `./designer` do not import it.
33
+
34
+ ## Layout
35
+
36
+ ```text
37
+ src/
38
+ adapter.ts VueAdapter: the per-version operations (h, text, mount,
39
+ set/del, refs, model, directives, unmountedHook, route
40
+ guards); set by
41
+ the vue2 / vue3 packages with setAdapter()
42
+ context/ renderer context (design mode, components, getNode)
43
+ renderer/
44
+ renderer.ts <Renderer>: picks the container renderer of the schema
45
+ renderers/ Page, Block and Component container renderers
46
+ use.ts node rendering (renderComp, props, slots, refs)
47
+ leaf.ts node state: split props / slots, designer subscriptions
48
+ root-scope/ `this` of a schema: state, methods, lifecycle, setup()
49
+ data-source/ data sources and the built-in fetch and jsonp handlers
50
+ shared/
51
+ schema.ts splitNodeSchema, event keys, v-model, loop arguments,
52
+ global data handler
53
+ ... expressions, assets, i18n, guards
54
+ simulator/ designer canvas: document instances, node lookup,
55
+ builtin components
56
+ ```
57
+
58
+ ## Rendering model
59
+
60
+ - Every node renders as its component's vnode (`h(comp, props, slots)`):
61
+ there is no wrapper component, so a component sees its children's vnodes
62
+ and instances (libraries reading `slots.default()` or `$children` work).
63
+ - Loops render their items as sibling vnodes; the condition is evaluated
64
+ before the loop, in the outer scope.
65
+ - Design mode: the node state comes from a store subscribed to the designer
66
+ node (`node.onPropChange` / `onChildrenChange`); it is read where the
67
+ node's vnode is created, so a change re-renders the node's container.
68
+ Instances are reported to the simulator through stable `ref` and
69
+ unmount-hook props.
70
+ - Vue 2: default slot content without slot props is passed as children (as
71
+ templates do), so `$slots.default` holds the rendered vnodes. Slots with
72
+ params are marked with `markScopedSlot`.
73
+
74
+ ## Schema semantics
75
+
76
+ `./schema` holds the rules both the renderer and the code generator follow
77
+ (children prop vs node children, `JSSlot` props, `onUpdateXxx` events,
78
+ `v-model[:arg]`, loop arguments, the global `dataHandler`).
79
+ `tests/conformance` renders fixtures with the renderer and with the
80
+ generated templates and runtime, on both Vue versions, and compares the
81
+ HTML, the method calls and the data source requests: change a rule in
82
+ `./schema` and both sides follow.
83
+
84
+ ## Tests
85
+
86
+ The suites in `tests/` run twice, once per Vue version (`vitest.config.ts`
87
+ at the repository root: projects `vue2` and `vue3`), with the adapter of
88
+ that version installed (`tests/setup`).
89
+
90
+ ```bash
91
+ pnpm exec vitest run --project vue2 --project vue3
92
+ ```
93
+
94
+ `tests/helpers/mount-renderer.ts` mounts a `Renderer` (live or design mode)
95
+ and builds test components that work on both versions.
96
+
97
+ ## License
98
+
99
+ [MIT](https://github.com/wuchendi/lowcode-engine-vue/blob/main/LICENSE)
@@ -0,0 +1,11 @@
1
+ import { IPublicApiProject } from "@alilc/lowcode-types";
2
+ interface DesignerEnvironment {
3
+ /** URL of the Vue runtime build that defines `window.Vue`. */
4
+ vue: string;
5
+ }
6
+ /**
7
+ * Loads Vue into the designer canvas before the simulator starts. Call it in
8
+ * the designer page before `init`.
9
+ */
10
+ declare function setupDesignerEnvironment(project: IPublicApiProject, environment: DesignerEnvironment): void;
11
+ export { setupDesignerEnvironment as n, DesignerEnvironment as t };
@@ -0,0 +1,2 @@
1
+ import { n as setupDesignerEnvironment, t as DesignerEnvironment } from "./designer-environment-4ZYec_hv.mjs";
2
+ export { DesignerEnvironment, setupDesignerEnvironment };
@@ -0,0 +1,19 @@
1
+ // src/shared/designer-environment.ts
2
+ /**
3
+ * Loads Vue into the designer canvas before the simulator starts. Call it in
4
+ * the designer page before `init`.
5
+ */
6
+ function setupDesignerEnvironment(project, environment) {
7
+ project.onSimulatorHostReady((host) => {
8
+ const assets = [{
9
+ type: "jsText",
10
+ content: "window.__is_simulator_env__=true;window.__VUE_DEVTOOLS_GLOBAL_HOOK__=window.parent.__VUE_DEVTOOLS_GLOBAL_HOOK__;"
11
+ }, {
12
+ type: "jsUrl",
13
+ content: environment.vue,
14
+ id: "vue"
15
+ }];
16
+ host.set("environment", assets);
17
+ });
18
+ }
19
+ export { setupDesignerEnvironment };
@@ -0,0 +1,60 @@
1
+ import { $ as clearExpressionCache, A as DataSourceItem, At as MemoryRouter, B as isJSExpression, Bt as getAdapter, C as findComponent, Ct as MaybeArray, D as RendererComponent, Dt as getRendererContextKey, E as LeafProps, Et as RendererContext, F as mergeScope, Ft as Slot, G as EXPRESSION_TYPE, Gt as setRouterAdapter, H as isJSSlot, Ht as isScopedSlot, I as evaluate, It as Slots, J as parseSchema, K as parseExpression, Kt as slotChildren, L as load, Lt as VNode, M as RequestHandlersMap, Mt as RouteGuard, N as RuntimeScope, Nt as RouteRecordInput, O as RendererProps, Ot as useRendererContext, P as isRuntimeScope, Pt as RouterAdapter, Q as getI18n, R as isDOMText, Rt as VueAdapter, S as componentSchemaOf, St as isAssetItem, T as isComponentSchema, Tt as DesignMode, U as isNodeSchema, Ut as markScopedSlot, V as isJSFunction, Vt as getRouterAdapter, W as rewriteThis, Wt as setAdapter, X as BlockScope, Y as parseSlotScope, Z as I18nMessages, _ as UtilsMetadata, _t as lowerFirst, a as schemaComponent, at as createDefer, b as accessLibrary, bt as assetItem, c as ComponentRenderer, ct as isCSSUrl, d as Renderer, dt as isFunction, et as evaluateExpression, f as RendererProps$1, ft as isNil, g as rendererConfig, gt as isString, h as RendererModules, ht as isPromise, i as declaredOptions, it as Defer, j as RequestHandler, jt as MountedApp, k as rendererProps, kt as ComponentInstance, l as PageRenderer, lt as isESModule, m as RendererConfig, mt as isPlainObject, n as useRenderer, nt as inSameDomain, o as isLifecycleKey, ot as ESModule, p as lowCodeComponent, pt as isObject, q as parseI18n, r as DeclaredOptions, rt as toDisplayString, s as BlockRenderer, st as camelize, t as useLeaf, tt as getExpressionCacheSize, u as RENDERER_COMPS, ut as isElement, v as buildUtils, vt as AssetLoader, w as getSubComponent, wt as ensureArray, x as buildComponents, xt as isAssetBundle, y as ComponentsMapItem, yt as StylePoint, z as isI18nData, zt as VueComponent } from "./runtime-DYXpKekm.mjs";
2
+ import { n as setupDesignerEnvironment, t as DesignerEnvironment } from "./designer-environment-4ZYec_hv.mjs";
3
+ import { IPublicTypeComponentSchema, IPublicTypeRootSchema } from "@alilc/lowcode-types";
4
+ import { BuiltinSimulatorHost, BuiltinSimulatorRenderer, DocumentModel, Node } from "@alilc/lowcode-designer";
5
+ interface SimulatorViewLayout {
6
+ Component?: VueComponent;
7
+ componentName?: string;
8
+ props?: Record<string, unknown>;
9
+ }
10
+ interface VueSimulatorRenderer extends Omit<BuiltinSimulatorRenderer, 'createComponent' | 'getComponent'> {
11
+ createComponent(schema: IPublicTypeComponentSchema): VueComponent | null;
12
+ getComponent(componentName: string): VueComponent | null;
13
+ app: MountedApp | null;
14
+ config: RendererConfig;
15
+ router: MemoryRouter;
16
+ layout: SimulatorViewLayout;
17
+ device: string;
18
+ locale: string | undefined;
19
+ designMode: string;
20
+ libraryMap: Record<string, string>;
21
+ components: Record<string, VueComponent>;
22
+ autoRender: boolean;
23
+ componentsMap: Record<string, ComponentsMapItem>;
24
+ documentInstances: DocumentInstance[];
25
+ requestHandlersMap: Record<string, CallableFunction>;
26
+ dispose(): void;
27
+ rerender(): void;
28
+ getCurrentDocument(): DocumentInstance | undefined;
29
+ }
30
+ interface DocumentInstance {
31
+ readonly id: string;
32
+ readonly key: string;
33
+ readonly path: string;
34
+ readonly scope: Record<string, unknown>;
35
+ readonly document: DocumentModel;
36
+ readonly instancesMap: Map<string, ComponentInstance[]>;
37
+ readonly schema: IPublicTypeRootSchema;
38
+ readonly messages: I18nMessages;
39
+ getComponentInstance(id: number): ComponentInstance | null;
40
+ mountInstance(id: string, instance: ComponentInstance | null): void;
41
+ unmountInstance(id: string, instance: ComponentInstance): void;
42
+ rerender(): void;
43
+ getNode(id: string): Node | null;
44
+ }
45
+ interface ProjectContext {
46
+ i18n: Record<string, object>;
47
+ appHelper: {
48
+ utils?: Record<string, unknown>;
49
+ constants?: Record<string, unknown>;
50
+ [x: string]: unknown;
51
+ };
52
+ }
53
+ export declare function createDocumentInstance(document: DocumentModel, context: ProjectContext, host: BuiltinSimulatorHost): DocumentInstance;
54
+ export declare function createSimulatorRenderer(host?: BuiltinSimulatorHost): VueSimulatorRenderer;
55
+ /**
56
+ * Creates the simulator for the canvas window and exposes it as
57
+ * `window.SimulatorRenderer`, where the designer host looks for it.
58
+ */
59
+ export declare function installSimulatorRenderer(host?: BuiltinSimulatorHost): VueSimulatorRenderer;
60
+ export { AssetLoader, BlockRenderer, type BlockScope, ComponentInstance, ComponentRenderer, type ComponentsMapItem, type RendererProps as ContainerRendererProps, type DataSourceItem, type DeclaredOptions, type Defer, DesignMode, type DesignerEnvironment, type DocumentInstance, type ESModule, EXPRESSION_TYPE, type I18nMessages, type LeafProps, type MaybeArray, MemoryRouter, MountedApp, PageRenderer, RENDERER_COMPS, Renderer, type RendererComponent, RendererConfig, RendererContext, type RendererModules, type RendererProps$1 as RendererProps, type RequestHandler, type RequestHandlersMap, RouteGuard, RouteRecordInput, RouterAdapter, type RuntimeScope, type SimulatorViewLayout, Slot, Slots, StylePoint, type UtilsMetadata, VNode, VueAdapter, VueComponent, type VueSimulatorRenderer, accessLibrary, assetItem, buildComponents, buildUtils, camelize, clearExpressionCache, componentSchemaOf, createDefer, declaredOptions, ensureArray, evaluateExpression, evaluate as evaluateScript, findComponent, getAdapter, getExpressionCacheSize, getI18n, getRendererContextKey, getRouterAdapter, getSubComponent, inSameDomain, isAssetBundle, isAssetItem, isCSSUrl, isComponentSchema, isDOMText, isESModule, isElement, isFunction, isI18nData, isJSExpression, isJSFunction, isJSSlot, isLifecycleKey, isNil, isNodeSchema, isObject, isPlainObject, isPromise, isRuntimeScope, isScopedSlot, isString, load as loadScript, lowCodeComponent, lowerFirst, markScopedSlot, mergeScope, parseExpression, parseI18n, parseSchema, parseSlotScope, rendererConfig, rendererProps, rewriteThis, schemaComponent, setAdapter, setRouterAdapter, setupDesignerEnvironment, slotChildren, toDisplayString, useLeaf, useRenderer, useRendererContext };