soma-core 1.0.2 → 1.0.3
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/app/SomaPageClient.tsx +31 -3
- package/app/api/page/route.ts +45 -25
- package/app/favicon.ico/route.ts +13 -0
- package/bin/soma.cjs +1 -1
- package/core/api/load-host-service.ts +5 -2
- package/core/compiler/page-base-resolver.ts +3 -0
- package/core/compiler/soma-manifest-webpack-plugin.js +124 -8
- package/core/engine/dom-renderer.ts +160 -24
- package/core/host/app-config.stub.ts +2 -0
- package/core/host/locale.stub.ts +2 -0
- package/core/host/source-packages.ts +112 -0
- package/dist/cli/soma.js +1 -1
- package/dist/core/index.cjs +99 -2
- package/dist/tsconfig.types.tsbuildinfo +1 -1
- package/dist/types/engine/dom-renderer.d.ts +6 -0
- package/dist/types/host/app-config.stub.d.ts +3 -0
- package/dist/types/host/locale.stub.d.ts +3 -0
- package/dist/types/host/source-packages.d.ts +8 -0
- package/global.d.ts +7 -7
- package/next.config.js +65 -1
- package/package.json +9 -5
- package/tailwind.config.ts +21 -17
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
export interface SomaAssetSource {
|
|
5
|
+
type: 'host' | 'package';
|
|
6
|
+
name: string;
|
|
7
|
+
assetRoot: string;
|
|
8
|
+
codeRoot: string;
|
|
9
|
+
packageName?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface PackageJson {
|
|
13
|
+
dependencies?: Record<string, string>;
|
|
14
|
+
devDependencies?: Record<string, string>;
|
|
15
|
+
soma?: {
|
|
16
|
+
source?: boolean;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function readJson<T>(filePath: string): T | null {
|
|
21
|
+
try {
|
|
22
|
+
if (!fs.existsSync(filePath)) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
return JSON.parse(fs.readFileSync(filePath, 'utf8')) as T;
|
|
26
|
+
} catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function packagePathInNodeModules(hostDir: string, packageName: string): string {
|
|
32
|
+
return path.join(hostDir, 'node_modules', ...packageName.split('/'));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function resolvePackageRoot(hostDir: string, packageName: string, version?: string): string | null {
|
|
36
|
+
const nodeModulesPath = packagePathInNodeModules(hostDir, packageName);
|
|
37
|
+
if (fs.existsSync(nodeModulesPath)) {
|
|
38
|
+
return nodeModulesPath;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (version?.startsWith('file:')) {
|
|
42
|
+
const fileRoot = path.resolve(hostDir, version.slice('file:'.length));
|
|
43
|
+
if (fs.existsSync(fileRoot)) {
|
|
44
|
+
return fileRoot;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function readExplicitSourcePackages(): string[] {
|
|
52
|
+
return String(process.env.SOMA_SOURCE_PACKAGES ?? '')
|
|
53
|
+
.split(',')
|
|
54
|
+
.map((item) => item.trim())
|
|
55
|
+
.filter(Boolean);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function readHostDependencies(hostDir: string): Record<string, string> {
|
|
59
|
+
const packageJson = readJson<PackageJson>(path.join(hostDir, 'package.json'));
|
|
60
|
+
return {
|
|
61
|
+
...(packageJson?.dependencies ?? {}),
|
|
62
|
+
...(packageJson?.devDependencies ?? {}),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function isSomaSourcePackage(packageRoot: string, explicit: boolean): boolean {
|
|
67
|
+
if (explicit) {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
const packageJson = readJson<PackageJson>(path.join(packageRoot, 'package.json'));
|
|
71
|
+
return packageJson?.soma?.source === true || fs.existsSync(path.join(packageRoot, 'shell', 'html'));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function toPackageSource(packageName: string, packageRoot: string): SomaAssetSource {
|
|
75
|
+
const shellRoot = path.join(packageRoot, 'shell');
|
|
76
|
+
return {
|
|
77
|
+
type: 'package',
|
|
78
|
+
name: packageName,
|
|
79
|
+
packageName,
|
|
80
|
+
assetRoot: fs.existsSync(path.join(shellRoot, 'html')) ? shellRoot : packageRoot,
|
|
81
|
+
codeRoot: packageRoot,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function getSomaAssetSources(hostDir: string): SomaAssetSource[] {
|
|
86
|
+
const normalizedHostDir = path.resolve(hostDir);
|
|
87
|
+
const dependencies = readHostDependencies(normalizedHostDir);
|
|
88
|
+
const explicitPackages = new Set(readExplicitSourcePackages());
|
|
89
|
+
const packageNames = new Set([
|
|
90
|
+
...Object.keys(dependencies),
|
|
91
|
+
...explicitPackages,
|
|
92
|
+
]);
|
|
93
|
+
|
|
94
|
+
const sources: SomaAssetSource[] = [
|
|
95
|
+
{
|
|
96
|
+
type: 'host',
|
|
97
|
+
name: 'host',
|
|
98
|
+
assetRoot: normalizedHostDir,
|
|
99
|
+
codeRoot: normalizedHostDir,
|
|
100
|
+
},
|
|
101
|
+
];
|
|
102
|
+
|
|
103
|
+
for (const packageName of packageNames) {
|
|
104
|
+
const packageRoot = resolvePackageRoot(normalizedHostDir, packageName, dependencies[packageName]);
|
|
105
|
+
if (!packageRoot || !isSomaSourcePackage(packageRoot, explicitPackages.has(packageName))) {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
sources.push(toPackageSource(packageName, packageRoot));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return sources;
|
|
112
|
+
}
|
package/dist/cli/soma.js
CHANGED
|
@@ -9,7 +9,7 @@ const node_path_1 = __importDefault(require("node:path"));
|
|
|
9
9
|
const args = process.argv.slice(2);
|
|
10
10
|
const command = args[0] || 'dev';
|
|
11
11
|
const delegated = ['doctor', 'sync', 'lsp', 'codegen', 'init', 'package-vscode'];
|
|
12
|
-
const packageRoot = node_path_1.default.resolve(__dirname, '
|
|
12
|
+
const packageRoot = node_path_1.default.resolve(__dirname, '../..');
|
|
13
13
|
function resolveNextBin() {
|
|
14
14
|
const searchPaths = [packageRoot, node_path_1.default.join(packageRoot, '..'), node_path_1.default.join(packageRoot, '../..')];
|
|
15
15
|
for (const base of searchPaths) {
|
package/dist/core/index.cjs
CHANGED
|
@@ -1148,7 +1148,7 @@ var SomaSnapshotStore = class {
|
|
|
1148
1148
|
}
|
|
1149
1149
|
};
|
|
1150
1150
|
|
|
1151
|
-
//
|
|
1151
|
+
// node_modules/js-yaml/dist/js-yaml.mjs
|
|
1152
1152
|
function isNothing(subject) {
|
|
1153
1153
|
return typeof subject === "undefined" || subject === null;
|
|
1154
1154
|
}
|
|
@@ -6040,7 +6040,12 @@ var SomaDomRenderer = class {
|
|
|
6040
6040
|
}
|
|
6041
6041
|
applyShowConfig(root, data, showConfig) {
|
|
6042
6042
|
for (const [rawKey, config] of Object.entries(showConfig)) {
|
|
6043
|
-
if (
|
|
6043
|
+
if (this.isNestedShowMapping(config)) {
|
|
6044
|
+
this.applyNestedShowConfig(root, data, rawKey, config);
|
|
6045
|
+
continue;
|
|
6046
|
+
}
|
|
6047
|
+
if (this.isExtendedShowValue(config)) {
|
|
6048
|
+
this.applyExtendedShowConfig(root, data, rawKey, config);
|
|
6044
6049
|
continue;
|
|
6045
6050
|
}
|
|
6046
6051
|
const [somaId, attrName] = rawKey.split("@");
|
|
@@ -6062,6 +6067,85 @@ var SomaDomRenderer = class {
|
|
|
6062
6067
|
this.adapter?.setText(element, value != null ? String(value) : "--");
|
|
6063
6068
|
}
|
|
6064
6069
|
}
|
|
6070
|
+
applyNestedShowConfig(root, data, rawKey, config) {
|
|
6071
|
+
if (!this.adapter) {
|
|
6072
|
+
return;
|
|
6073
|
+
}
|
|
6074
|
+
const [somaId] = rawKey.split("@");
|
|
6075
|
+
const element = root.querySelector(`[data-soma-id="${somaId}"]`);
|
|
6076
|
+
if (!element) {
|
|
6077
|
+
return;
|
|
6078
|
+
}
|
|
6079
|
+
const nestedData = this.resolveShowValue(config.bind.obj, data);
|
|
6080
|
+
const role = this.adapter.readRole(element);
|
|
6081
|
+
const templateCache = this.adapter.cloneTemplate(element);
|
|
6082
|
+
if (!templateCache) {
|
|
6083
|
+
return;
|
|
6084
|
+
}
|
|
6085
|
+
this.adapter.clearRenderedChildren(element);
|
|
6086
|
+
if (Array.isArray(nestedData) || role === "item") {
|
|
6087
|
+
const items = Array.isArray(nestedData) ? nestedData : [];
|
|
6088
|
+
for (const itemData of items) {
|
|
6089
|
+
this.appendNestedTemplateItem(element, templateCache, itemData, config.show);
|
|
6090
|
+
}
|
|
6091
|
+
return;
|
|
6092
|
+
}
|
|
6093
|
+
if (nestedData && typeof nestedData === "object") {
|
|
6094
|
+
this.appendNestedTemplateItem(element, templateCache, nestedData, config.show);
|
|
6095
|
+
}
|
|
6096
|
+
}
|
|
6097
|
+
appendNestedTemplateItem(container, templateCache, itemData, showConfig) {
|
|
6098
|
+
if (!this.adapter) {
|
|
6099
|
+
return;
|
|
6100
|
+
}
|
|
6101
|
+
const fragment = templateCache.cloneNode(true);
|
|
6102
|
+
const wrapper = fragment.firstElementChild;
|
|
6103
|
+
if (!wrapper) {
|
|
6104
|
+
return;
|
|
6105
|
+
}
|
|
6106
|
+
if (itemData && typeof itemData === "object") {
|
|
6107
|
+
const key = "id" in itemData ? itemData.id : "key" in itemData ? itemData.key : void 0;
|
|
6108
|
+
if (key != null) {
|
|
6109
|
+
wrapper.setAttribute("data-soma-key", String(key));
|
|
6110
|
+
}
|
|
6111
|
+
}
|
|
6112
|
+
this.scopeTracker?.set(wrapper, itemData);
|
|
6113
|
+
this.applyShowConfig(wrapper, itemData, showConfig);
|
|
6114
|
+
this.adapter.appendFragment(container, fragment);
|
|
6115
|
+
}
|
|
6116
|
+
applyExtendedShowConfig(root, data, rawKey, config) {
|
|
6117
|
+
const [somaId, attrName] = rawKey.split("@");
|
|
6118
|
+
const element = root.querySelector(`[data-soma-id="${somaId}"]`);
|
|
6119
|
+
if (element) {
|
|
6120
|
+
if (config.text) {
|
|
6121
|
+
const value = this.resolveShowValue(config.text, data);
|
|
6122
|
+
if (attrName === "html") {
|
|
6123
|
+
this.adapter?.setHtml(element, String(value ?? ""));
|
|
6124
|
+
} else if (attrName) {
|
|
6125
|
+
if (value != null) {
|
|
6126
|
+
this.adapter?.setAttribute(element, attrName, String(value));
|
|
6127
|
+
}
|
|
6128
|
+
} else {
|
|
6129
|
+
this.adapter?.setText(element, value != null ? String(value) : "--");
|
|
6130
|
+
}
|
|
6131
|
+
}
|
|
6132
|
+
if (config.when) {
|
|
6133
|
+
const { path, negate } = this.parseConditionalPath(config.when);
|
|
6134
|
+
const value = this.resolveShowValue(path, data);
|
|
6135
|
+
this.adapter?.setVisibility(element, negate ? !value : !!value);
|
|
6136
|
+
}
|
|
6137
|
+
if (config.class) {
|
|
6138
|
+
for (const [classes, path] of Object.entries(config.class)) {
|
|
6139
|
+
const enabled = !!this.resolveShowValue(path, data);
|
|
6140
|
+
this.adapter?.toggleClasses(element, classes.split(" ").filter(Boolean), enabled);
|
|
6141
|
+
}
|
|
6142
|
+
}
|
|
6143
|
+
}
|
|
6144
|
+
if (config.show) {
|
|
6145
|
+
const showRoot = element ?? root;
|
|
6146
|
+
this.applyShowConfig(showRoot, data, config.show);
|
|
6147
|
+
}
|
|
6148
|
+
}
|
|
6065
6149
|
resolveShowValue(valuePath, itemData) {
|
|
6066
6150
|
const segments = valuePath.split(".");
|
|
6067
6151
|
const firstSeg = segments[0];
|
|
@@ -6074,6 +6158,19 @@ var SomaDomRenderer = class {
|
|
|
6074
6158
|
}
|
|
6075
6159
|
return segments.reduce((obj, key) => obj?.[key], itemData);
|
|
6076
6160
|
}
|
|
6161
|
+
parseConditionalPath(valuePath) {
|
|
6162
|
+
const negate = valuePath.startsWith("!");
|
|
6163
|
+
return {
|
|
6164
|
+
path: negate ? valuePath.slice(1) : valuePath,
|
|
6165
|
+
negate
|
|
6166
|
+
};
|
|
6167
|
+
}
|
|
6168
|
+
isNestedShowMapping(value) {
|
|
6169
|
+
return typeof value === "object" && value !== null && "bind" in value && "show" in value;
|
|
6170
|
+
}
|
|
6171
|
+
isExtendedShowValue(value) {
|
|
6172
|
+
return typeof value === "object" && value !== null;
|
|
6173
|
+
}
|
|
6077
6174
|
};
|
|
6078
6175
|
|
|
6079
6176
|
// core/engine/property-watcher.ts
|