@owdproject/core 3.4.0 → 4.0.0-alpha.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.
Files changed (108) hide show
  1. package/README.md +112 -13
  2. package/dist/dom/index.d.mts +65 -0
  3. package/dist/dom/index.d.ts +65 -0
  4. package/dist/dom/index.mjs +224 -0
  5. package/dist/events/index.d.mts +70 -0
  6. package/dist/events/index.d.ts +70 -0
  7. package/dist/events/index.mjs +3 -0
  8. package/dist/index.d.mts +73 -0
  9. package/dist/index.d.ts +73 -0
  10. package/dist/index.mjs +115 -0
  11. package/dist/layout/index.d.mts +41 -0
  12. package/dist/layout/index.d.ts +41 -0
  13. package/dist/layout/index.mjs +64 -0
  14. package/dist/machines/index.d.mts +31 -0
  15. package/dist/machines/index.d.ts +31 -0
  16. package/dist/machines/index.mjs +2 -0
  17. package/dist/managers/index.d.mts +117 -0
  18. package/dist/managers/index.d.ts +117 -0
  19. package/dist/managers/index.mjs +6 -0
  20. package/dist/session/index.d.mts +57 -0
  21. package/dist/session/index.d.ts +57 -0
  22. package/dist/session/index.mjs +65 -0
  23. package/dist/shared/core.B0B0KfVK.mjs +865 -0
  24. package/dist/shared/core.B1XxB289.mjs +239 -0
  25. package/dist/shared/core.B3mp7ztE.mjs +237 -0
  26. package/dist/shared/core.BOvFdEVQ.d.ts +114 -0
  27. package/dist/shared/core.CsDFgGnX.mjs +40 -0
  28. package/dist/shared/core.Di1eFcr_.d.mts +114 -0
  29. package/dist/shared/core.Pd_Ogt4g.mjs +101 -0
  30. package/dist/shared/core.b3Xldzyu.mjs +29 -0
  31. package/dist/types/index.d.mts +266 -0
  32. package/dist/types/index.d.ts +266 -0
  33. package/dist/types/index.mjs +1 -0
  34. package/package.json +56 -112
  35. package/CHANGELOG.md +0 -98
  36. package/DESKTOP_KERNEL.md +0 -232
  37. package/MIGRATION_3.3.2.md +0 -23
  38. package/MIGRATION_3.4.md +0 -126
  39. package/PLAYGROUND.md +0 -91
  40. package/dist/module.d.mts +0 -13
  41. package/dist/module.json +0 -9
  42. package/dist/module.mjs +0 -254
  43. package/dist/types.d.mts +0 -7
  44. package/index.ts +0 -8
  45. package/kit/authoring.ts +0 -340
  46. package/kit/defineDesktopApp.ts +0 -56
  47. package/module.ts +0 -203
  48. package/runtime/components/Application/DesktopCoreApplicationRender.vue +0 -20
  49. package/runtime/components/Application/DesktopCoreApplicationWindowsRender.vue +0 -38
  50. package/runtime/components/background/DesktopCoreBackground.vue +0 -16
  51. package/runtime/components/core/DesktopCore.vue +0 -43
  52. package/runtime/components/time/DesktopCoreTime.vue +0 -56
  53. package/runtime/components/window/DesktopCoreWindow.vue +0 -215
  54. package/runtime/components/window/DesktopCoreWindowContent.vue +0 -28
  55. package/runtime/components/window/DesktopCoreWindowNav.vue +0 -66
  56. package/runtime/components/window/DesktopCoreWindowSnapHintsBase.vue +0 -74
  57. package/runtime/components/workspace/DesktopCoreWorkspaceEdgeHintsBase.vue +0 -84
  58. package/runtime/composables/useApplicationEntries.ts +0 -51
  59. package/runtime/composables/useApplicationManager.ts +0 -285
  60. package/runtime/composables/useBlockNonInputContextMenu.ts +0 -30
  61. package/runtime/composables/useDesktopConfig.ts +0 -8
  62. package/runtime/composables/useDesktopDialogs.ts +0 -16
  63. package/runtime/composables/useDesktopExtension.ts +0 -8
  64. package/runtime/composables/useDesktopManager.ts +0 -51
  65. package/runtime/composables/useDesktopManifest.ts +0 -17
  66. package/runtime/composables/useDesktopSession.ts +0 -27
  67. package/runtime/composables/useDesktopShellIdentity.ts +0 -99
  68. package/runtime/composables/useDesktopShellOptions.ts +0 -36
  69. package/runtime/composables/useDesktopShellReady.ts +0 -7
  70. package/runtime/composables/useDesktopWorkArea.ts +0 -93
  71. package/runtime/composables/useTerminalManager.ts +0 -159
  72. package/runtime/composables/useToggleWindowMaximize.ts +0 -35
  73. package/runtime/composables/useWindowDragHandlers.ts +0 -47
  74. package/runtime/composables/useWindowSnapDrop.ts +0 -112
  75. package/runtime/composables/useWorkspaceEdgeDrop.ts +0 -176
  76. package/runtime/composables/useWorkspaceManager.ts +0 -67
  77. package/runtime/composables/useWorkspaceOverviewCapture.ts +0 -92
  78. package/runtime/composables/useWorkspaceOverviewLiveScale.ts +0 -151
  79. package/runtime/constants/desktopShellKeys.ts +0 -12
  80. package/runtime/constants/shellLayout.ts +0 -5
  81. package/runtime/dialogs/desktopDialogProvider.ts +0 -73
  82. package/runtime/internal/controllers/ApplicationController.ts +0 -351
  83. package/runtime/internal/controllers/WindowController.ts +0 -547
  84. package/runtime/plugins/01.desktop-shell-init.client.ts +0 -28
  85. package/runtime/plugins/02.desktop-register-desktop-apps.client.ts +0 -13
  86. package/runtime/plugins/resize.client.ts +0 -6
  87. package/runtime/stores/storeApplicationMeta.ts +0 -60
  88. package/runtime/stores/storeApplicationWindows.ts +0 -21
  89. package/runtime/stores/storeDesktop.ts +0 -71
  90. package/runtime/stores/storeDesktopDefaultApps.ts +0 -54
  91. package/runtime/stores/storeDesktopVolume.ts +0 -19
  92. package/runtime/stores/storeDesktopWindow.ts +0 -38
  93. package/runtime/stores/storeDesktopWorkspace.ts +0 -105
  94. package/runtime/stores/storeIds.ts +0 -35
  95. package/runtime/types/desktopMenu.ts +0 -10
  96. package/runtime/utils/initDesktopShell.ts +0 -80
  97. package/runtime/utils/migratePersistedStoreIds.ts +0 -57
  98. package/runtime/utils/utilApp.ts +0 -25
  99. package/runtime/utils/utilCaptureElementToCanvas.ts +0 -21
  100. package/runtime/utils/utilCommon.ts +0 -26
  101. package/runtime/utils/utilDebug.ts +0 -30
  102. package/runtime/utils/utilDetectSnapZone.ts +0 -57
  103. package/runtime/utils/utilTerminal.ts +0 -6
  104. package/runtime/utils/utilWindowControllerAdapter.ts +0 -15
  105. package/runtime/utils/utilWindowLayout.ts +0 -82
  106. package/runtime/utils/utilWindowMaximizeLayout.ts +0 -44
  107. package/runtime/utils/utilWorkspaceWindows.ts +0 -33
  108. package/types/index.d.ts +0 -531
package/dist/module.mjs DELETED
@@ -1,254 +0,0 @@
1
- import { installModule, defineNuxtModule, createResolver, resolvePath, addComponentsDir, addPlugin, addImportsDir } from '@nuxt/kit';
2
- import { defu } from 'defu';
3
- import { existsSync } from 'node:fs';
4
- import { join } from 'node:path';
5
-
6
- function assertValidDesktopUserConfig(config, configFile = "desktop.config.ts") {
7
- if (!config || typeof config !== "object" || Array.isArray(config)) {
8
- throw new Error(
9
- `[@owdproject/core] ${configFile} must default-export a non-array object from defineDesktopConfig({ ... }).`
10
- );
11
- }
12
- const c = config;
13
- if (c.theme != null && typeof c.theme !== "string") {
14
- throw new Error(
15
- `[@owdproject/core] ${configFile}: \`theme\` must be a string (npm package name of the theme module).`
16
- );
17
- }
18
- if (c.apps !== void 0) {
19
- if (!Array.isArray(c.apps) || !c.apps.every((item) => typeof item === "string")) {
20
- throw new Error(
21
- `[@owdproject/core] ${configFile}: \`apps\` must be an array of strings (Nuxt module package names).`
22
- );
23
- }
24
- }
25
- if (c.modules !== void 0) {
26
- if (!Array.isArray(c.modules) || !c.modules.every((item) => typeof item === "string")) {
27
- throw new Error(
28
- `[@owdproject/core] ${configFile}: \`modules\` must be an array of strings (Nuxt module package names).`
29
- );
30
- }
31
- }
32
- }
33
- const DESKTOP_CONFIG_FILENAME = "desktop.config.ts";
34
- const LEGACY_DESKTOP_CONFIG_FILENAME = "owd.config.ts";
35
- const LEGACY_CONFIG_DEPRECATION = "[@owdproject/core] owd.config.ts is deprecated and kept only for backward compatibility; rename to desktop.config.ts (required from @owdproject/core 3.2).";
36
- function resolveDesktopConfigPath(rootDir) {
37
- const desktopPath = join(rootDir, DESKTOP_CONFIG_FILENAME);
38
- const legacyPath = join(rootDir, LEGACY_DESKTOP_CONFIG_FILENAME);
39
- const hasDesktop = existsSync(desktopPath);
40
- const hasLegacy = existsSync(legacyPath);
41
- if (hasDesktop && hasLegacy) {
42
- console.warn(
43
- "[@owdproject/core] Both desktop.config.ts and owd.config.ts exist; using desktop.config.ts. Remove owd.config.ts."
44
- );
45
- return { path: desktopPath, file: DESKTOP_CONFIG_FILENAME, legacy: false };
46
- }
47
- if (hasDesktop) {
48
- return { path: desktopPath, file: DESKTOP_CONFIG_FILENAME, legacy: false };
49
- }
50
- if (hasLegacy) {
51
- return {
52
- path: legacyPath,
53
- file: LEGACY_DESKTOP_CONFIG_FILENAME,
54
- legacy: true
55
- };
56
- }
57
- return null;
58
- }
59
- function warnLegacyDesktopConfig(resolved) {
60
- if (resolved?.legacy) {
61
- console.warn(LEGACY_CONFIG_DEPRECATION);
62
- }
63
- }
64
- const NUXT_OPTION_KEYS = /* @__PURE__ */ new Set([
65
- "ssr",
66
- "devtools",
67
- "vite",
68
- "nitro",
69
- "runtimeConfig",
70
- "app",
71
- "appConfig",
72
- "css",
73
- "plugins",
74
- "hooks",
75
- "extends",
76
- "compatibilityDate",
77
- "experimental",
78
- "future",
79
- "i18n",
80
- "tailwindcss",
81
- "primevue"
82
- ]);
83
- function warnDesktopConfigKeys(config, configFile = "desktop.config.ts") {
84
- for (const key of Object.keys(config)) {
85
- if (NUXT_OPTION_KEYS.has(key)) {
86
- console.warn(
87
- `[@owdproject/core] ${configFile}: key "${key}" looks like a Nuxt option and is ignored for _nuxt.options. Move it to nuxt.config.ts; shell values belong under defineDesktopConfig({ systemBar, workspaces, ... }).`
88
- );
89
- }
90
- }
91
- }
92
- function readConfigKey(mod) {
93
- const key = mod?.meta?.configKey ?? mod?.default?.meta?.configKey;
94
- return typeof key === "string" && key.length > 0 ? key : void 0;
95
- }
96
- async function loadModuleDescriptor(modulePath) {
97
- try {
98
- const imported = await import(modulePath);
99
- return imported.default ?? imported;
100
- } catch (e) {
101
- console.warn(`[@owdproject/core] Failed to load module descriptor for "${modulePath}":`, e.message || e);
102
- return void 0;
103
- }
104
- }
105
- async function installDesktopPackage(nuxt, modulePath, desktop) {
106
- const descriptor = await loadModuleDescriptor(modulePath);
107
- const configKey = readConfigKey(descriptor);
108
- if (configKey && desktop) {
109
- const slice = desktop[configKey];
110
- const inline = slice && typeof slice === "object" && !Array.isArray(slice) ? slice : {};
111
- await installModule(modulePath, inline);
112
- return;
113
- }
114
- await installModule(modulePath);
115
- }
116
-
117
- const version = "3.4.0";
118
- const pkg = {
119
- version: version};
120
-
121
- const module$1 = defineNuxtModule({
122
- meta: {
123
- name: "desktop",
124
- configKey: "desktop"
125
- },
126
- defaults: {
127
- theme: "@owdproject/theme-nova",
128
- apps: [],
129
- modules: []
130
- },
131
- moduleDependencies: {
132
- "@pinia/nuxt": {},
133
- "@nuxt/fonts": {},
134
- "@nuxt/icon": {
135
- defaults: {
136
- clientBundle: {
137
- scan: true,
138
- sizeLimitKb: 256
139
- }
140
- }
141
- },
142
- "@vueuse/nuxt": {},
143
- "@nuxtjs/i18n": {}
144
- },
145
- async setup(_options, _nuxt) {
146
- const { resolve } = createResolver(import.meta.url);
147
- let resolvedNanoid = null;
148
- try {
149
- resolvedNanoid = await resolvePath("nanoid", { url: import.meta.url });
150
- } catch (e) {
151
- }
152
- _nuxt.options.experimental = {
153
- ..._nuxt.options.experimental,
154
- viteEnvironmentApi: _nuxt.options.experimental?.viteEnvironmentApi ?? true
155
- };
156
- _nuxt.options.runtimeConfig.public.desktop = {};
157
- let clientConfig;
158
- const resolvedConfig = resolveDesktopConfigPath(_nuxt.options.rootDir);
159
- if (!resolvedConfig) {
160
- const hint = "Create desktop.config.ts next to your Nuxt root (e.g. desktop/desktop.config.ts), export default defineDesktopConfig({ theme, apps, modules }).";
161
- throw new Error(`[@owdproject/core] Cannot find desktop.config.ts in ${_nuxt.options.rootDir}. ${hint}`);
162
- }
163
- warnLegacyDesktopConfig(resolvedConfig);
164
- _nuxt.options.watch ??= [];
165
- _nuxt.options.watch.push(resolvedConfig.path);
166
- try {
167
- clientConfig = (await import(resolvedConfig.path)).default;
168
- } catch (e) {
169
- const hint = "Export default defineDesktopConfig({ theme, apps, modules }) from desktop.config.ts.";
170
- throw new Error(
171
- `[@owdproject/core] Cannot load ${resolvedConfig.file}. ${hint}`,
172
- { cause: e }
173
- );
174
- }
175
- assertValidDesktopUserConfig(clientConfig, resolvedConfig.file);
176
- if (!clientConfig.theme) {
177
- clientConfig.theme = "@owdproject/theme-nova";
178
- }
179
- const configRecord = clientConfig;
180
- warnDesktopConfigKeys(configRecord, resolvedConfig.file);
181
- const desktop = defu(configRecord, { coreVersion: pkg.version });
182
- _nuxt.options.runtimeConfig.public.desktop = desktop;
183
- {
184
- if (desktop.theme) {
185
- try {
186
- await installDesktopPackage(_nuxt, desktop.theme, desktop);
187
- } catch (e) {
188
- const msg = e instanceof Error ? e.message : String(e);
189
- console.warn(`[@owdproject/core] Warning: Could not load theme "${desktop.theme}". Details: ${msg}`);
190
- }
191
- }
192
- if (Array.isArray(desktop.modules)) {
193
- for (const modulePath of desktop.modules) {
194
- try {
195
- await installDesktopPackage(_nuxt, modulePath, desktop);
196
- } catch (e) {
197
- const msg = e instanceof Error ? e.message : String(e);
198
- console.warn(`[@owdproject/core] Warning: Could not load module "${modulePath}". Details: ${msg}`);
199
- }
200
- }
201
- }
202
- if (Array.isArray(desktop.apps)) {
203
- for (const appPath of desktop.apps) {
204
- try {
205
- await installDesktopPackage(_nuxt, appPath, desktop);
206
- } catch (e) {
207
- const msg = e instanceof Error ? e.message : String(e);
208
- console.warn(`[@owdproject/core] Warning: Could not load app "${appPath}". Details: ${msg}`);
209
- }
210
- }
211
- }
212
- }
213
- _nuxt.options.appConfig.desktop = _nuxt.options.runtimeConfig.public.desktop;
214
- {
215
- _nuxt.hook("vite:extendConfig", (viteConfig) => {
216
- viteConfig.css = viteConfig.css || {};
217
- viteConfig.css.preprocessorOptions = viteConfig.css.preprocessorOptions || {};
218
- viteConfig.css.preprocessorOptions.scss = {
219
- api: "modern-compiler"
220
- };
221
- viteConfig.optimizeDeps = viteConfig.optimizeDeps || {};
222
- viteConfig.optimizeDeps.include = viteConfig.optimizeDeps.include || [];
223
- if (resolvedNanoid && !viteConfig.optimizeDeps.include.includes(resolvedNanoid)) {
224
- viteConfig.optimizeDeps.include.push(resolvedNanoid);
225
- }
226
- });
227
- }
228
- {
229
- _nuxt.options.css.push("sanitize.css");
230
- }
231
- {
232
- addComponentsDir({
233
- path: resolve("./runtime/components"),
234
- prefix: "Desktop",
235
- pathPrefix: false,
236
- global: true
237
- });
238
- }
239
- {
240
- addPlugin(resolve("./runtime/plugins/resize.client.ts"));
241
- addPlugin(
242
- resolve("./runtime/plugins/01.desktop-shell-init.client.ts")
243
- );
244
- addPlugin(
245
- resolve("./runtime/plugins/02.desktop-register-desktop-apps.client.ts")
246
- );
247
- addImportsDir(resolve("./runtime/composables"));
248
- addImportsDir(resolve("./runtime/stores"));
249
- addImportsDir(resolve("./runtime/utils"));
250
- }
251
- }
252
- });
253
-
254
- export { module$1 as default };
package/dist/types.d.mts DELETED
@@ -1,7 +0,0 @@
1
- import type { NuxtModule } from '@nuxt/schema'
2
-
3
- import type { default as Module } from './module.mjs'
4
-
5
- export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
6
-
7
- export { default } from './module.mjs'
package/index.ts DELETED
@@ -1,8 +0,0 @@
1
- export { defineDesktopApp } from './kit/defineDesktopApp'
2
- export {
3
- defineDesktopConfig,
4
- defineDesktopModule,
5
- defineDesktopTheme,
6
- mergeDesktopExtensionConfig,
7
- setDesktopExtensionConfig,
8
- } from './kit/authoring'
package/kit/authoring.ts DELETED
@@ -1,340 +0,0 @@
1
- import { existsSync } from 'node:fs'
2
- import { join } from 'node:path'
3
-
4
- import {
5
- defineNuxtModule,
6
- installModule,
7
- type NuxtModule,
8
- } from '@nuxt/kit'
9
- import type { Nuxt } from '@nuxt/schema'
10
- import { defu } from 'defu'
11
-
12
- /** Root `desktop.config.ts` helper — keep this file free of `import.meta` for jiti. */
13
- export function defineDesktopConfig(config: DesktopConfig) {
14
- return config
15
- }
16
-
17
- /**
18
- * Runtime validation for the object exported from `desktop.config.ts`
19
- * (or legacy `owd.config.ts`).
20
- */
21
- export function assertValidDesktopUserConfig(
22
- config: unknown,
23
- configFile = 'desktop.config.ts',
24
- ): void {
25
- if (!config || typeof config !== 'object' || Array.isArray(config)) {
26
- throw new Error(
27
- `[@owdproject/core] ${configFile} must default-export a non-array object from defineDesktopConfig({ ... }).`,
28
- )
29
- }
30
-
31
- const c = config as Record<string, unknown>
32
-
33
- if (c.theme != null && typeof c.theme !== 'string') {
34
- throw new Error(
35
- `[@owdproject/core] ${configFile}: \`theme\` must be a string (npm package name of the theme module).`,
36
- )
37
- }
38
-
39
- if (c.apps !== undefined) {
40
- if (
41
- !Array.isArray(c.apps) ||
42
- !(c.apps as unknown[]).every((item) => typeof item === 'string')
43
- ) {
44
- throw new Error(
45
- `[@owdproject/core] ${configFile}: \`apps\` must be an array of strings (Nuxt module package names).`,
46
- )
47
- }
48
- }
49
-
50
- if (c.modules !== undefined) {
51
- if (
52
- !Array.isArray(c.modules) ||
53
- !(c.modules as unknown[]).every((item) => typeof item === 'string')
54
- ) {
55
- throw new Error(
56
- `[@owdproject/core] ${configFile}: \`modules\` must be an array of strings (Nuxt module package names).`,
57
- )
58
- }
59
- }
60
- }
61
-
62
- export const DESKTOP_CONFIG_FILENAME = 'desktop.config.ts'
63
- export const LEGACY_DESKTOP_CONFIG_FILENAME = 'owd.config.ts'
64
-
65
- export const LEGACY_CONFIG_DEPRECATION =
66
- '[@owdproject/core] owd.config.ts is deprecated and kept only for backward compatibility; rename to desktop.config.ts (required from @owdproject/core 3.2).'
67
-
68
- export type ResolvedDesktopConfigPath = {
69
- path: string
70
- file: string
71
- legacy: boolean
72
- }
73
-
74
- export function resolveDesktopConfigPath(
75
- rootDir: string,
76
- ): ResolvedDesktopConfigPath | null {
77
- const desktopPath = join(rootDir, DESKTOP_CONFIG_FILENAME)
78
- const legacyPath = join(rootDir, LEGACY_DESKTOP_CONFIG_FILENAME)
79
- const hasDesktop = existsSync(desktopPath)
80
- const hasLegacy = existsSync(legacyPath)
81
-
82
- if (hasDesktop && hasLegacy) {
83
- console.warn(
84
- '[@owdproject/core] Both desktop.config.ts and owd.config.ts exist; using desktop.config.ts. Remove owd.config.ts.',
85
- )
86
- return { path: desktopPath, file: DESKTOP_CONFIG_FILENAME, legacy: false }
87
- }
88
-
89
- if (hasDesktop) {
90
- return { path: desktopPath, file: DESKTOP_CONFIG_FILENAME, legacy: false }
91
- }
92
-
93
- if (hasLegacy) {
94
- return {
95
- path: legacyPath,
96
- file: LEGACY_DESKTOP_CONFIG_FILENAME,
97
- legacy: true,
98
- }
99
- }
100
-
101
- return null
102
- }
103
-
104
- export function warnLegacyDesktopConfig(
105
- resolved: ResolvedDesktopConfigPath | null | undefined,
106
- ): void {
107
- if (resolved?.legacy) {
108
- console.warn(LEGACY_CONFIG_DEPRECATION)
109
- }
110
- }
111
-
112
- /** Path used when creating or updating config from the CLI (always the new filename). */
113
- export function desktopConfigWritePath(desktopDir: string): string {
114
- return join(desktopDir, DESKTOP_CONFIG_FILENAME)
115
- }
116
-
117
- /** Nuxt top-level option names — warn if present in desktop.config (likely misconfiguration). */
118
- const NUXT_OPTION_KEYS = new Set([
119
- 'ssr',
120
- 'devtools',
121
- 'vite',
122
- 'nitro',
123
- 'runtimeConfig',
124
- 'app',
125
- 'appConfig',
126
- 'css',
127
- 'plugins',
128
- 'hooks',
129
- 'extends',
130
- 'compatibilityDate',
131
- 'experimental',
132
- 'future',
133
- 'i18n',
134
- 'tailwindcss',
135
- 'primevue',
136
- ])
137
-
138
- /**
139
- * Warn when desktop.config.ts contains keys that look like Nuxt options.
140
- * Extension keys (fs, terminal, custom app namespaces) are intentionally not validated here.
141
- */
142
- export function warnDesktopConfigKeys(
143
- config: Record<string, unknown>,
144
- configFile = 'desktop.config.ts',
145
- ): void {
146
- for (const key of Object.keys(config)) {
147
- if (NUXT_OPTION_KEYS.has(key)) {
148
- console.warn(
149
- `[@owdproject/core] ${configFile}: key "${key}" looks like a Nuxt option and is ignored for _nuxt.options. Move it to nuxt.config.ts; shell values belong under defineDesktopConfig({ systemBar, workspaces, ... }).`,
150
- )
151
- }
152
- }
153
- }
154
-
155
- /**
156
- * Writes a resolved extension namespace to `runtimeConfig.public.desktop[configKey]`.
157
- * Used by {@link defineDesktopModule} after Nuxt merges inline options with module defaults.
158
- */
159
- export function setDesktopExtensionConfig(
160
- nuxt: Nuxt,
161
- configKey: string,
162
- resolved: Record<string, unknown>,
163
- ): void {
164
- const pub = (nuxt.options.runtimeConfig.public ??= {}) as {
165
- desktop?: Record<string, unknown>
166
- }
167
- const desktop = (pub.desktop ??= {})
168
- desktop[configKey] = resolved
169
- }
170
-
171
- /**
172
- * Merges theme or module defaults into an extension namespace on `public.desktop`.
173
- * User values from desktop.config win over `partial` (defu: partial fills undefined only).
174
- */
175
- export function mergeDesktopExtensionConfig(
176
- nuxt: Nuxt,
177
- configKey: string,
178
- partial: Record<string, unknown>,
179
- ): void {
180
- const pub = (nuxt.options.runtimeConfig.public ??= {}) as {
181
- desktop?: Record<string, unknown>
182
- }
183
- const desktop = (pub.desktop ??= {})
184
- const existing = desktop[configKey]
185
- const base =
186
- existing && typeof existing === 'object' && !Array.isArray(existing)
187
- ? (existing as Record<string, unknown>)
188
- : {}
189
- desktop[configKey] = defu(partial, base)
190
- }
191
-
192
- type ModuleLike = {
193
- meta?: { configKey?: string }
194
- default?: { meta?: { configKey?: string } }
195
- }
196
-
197
- function readConfigKey(mod: ModuleLike | undefined): string | undefined {
198
- const key = mod?.meta?.configKey ?? mod?.default?.meta?.configKey
199
- return typeof key === 'string' && key.length > 0 ? key : undefined
200
- }
201
-
202
- async function loadModuleDescriptor(
203
- modulePath: string,
204
- ): Promise<ModuleLike | undefined> {
205
- try {
206
- const imported = await import(modulePath)
207
- return (imported as { default?: ModuleLike }).default ?? imported
208
- } catch (e: any) {
209
- console.warn(`[@owdproject/core] Failed to load module descriptor for "${modulePath}":`, e.message || e)
210
- return undefined
211
- }
212
- }
213
-
214
- /**
215
- * Installs a desktop theme, module, or app package.
216
- * When the package exposes `meta.configKey`, passes `desktop[configKey]` to `installModule`
217
- * so Nuxt merges desktop.config with module defaults.
218
- */
219
- export async function installDesktopPackage(
220
- nuxt: Nuxt,
221
- modulePath: string,
222
- desktop?: Record<string, unknown>,
223
- ): Promise<void> {
224
- const descriptor = await loadModuleDescriptor(modulePath)
225
- const configKey = readConfigKey(descriptor)
226
-
227
- if (configKey && desktop) {
228
- const slice = desktop[configKey]
229
- const inline =
230
- slice && typeof slice === 'object' && !Array.isArray(slice)
231
- ? (slice as Record<string, unknown>)
232
- : {}
233
- await installModule(modulePath, inline)
234
- return
235
- }
236
-
237
- await installModule(modulePath)
238
- }
239
-
240
- type DesktopModuleMeta = {
241
- name: string
242
- configKey: string
243
- }
244
-
245
- type DesktopModuleDefinition = NuxtModule<
246
- Record<string, unknown>,
247
- Record<string, unknown>,
248
- false
249
- > & {
250
- meta: DesktopModuleMeta
251
- }
252
-
253
- /**
254
- * Nuxt module wrapper for desktop apps and extension modules (`configKey` → desktop.config namespace).
255
- * Publishes merged options to `runtimeConfig.public.desktop[configKey]` after setup runs.
256
- */
257
- export function defineDesktopModule(
258
- definition: DesktopModuleDefinition,
259
- ): ReturnType<typeof defineNuxtModule> {
260
- const configKey = definition.meta.configKey
261
- if (!configKey) {
262
- throw new Error(
263
- '[@owdproject/core] defineDesktopModule requires meta.configKey (e.g. "terminal", "fs").',
264
- )
265
- }
266
-
267
- const userSetup = definition.setup
268
-
269
- return defineNuxtModule({
270
- ...definition,
271
- async setup(options, nuxt) {
272
- const pub = (nuxt.options.runtimeConfig.public ??= {}) as {
273
- desktop?: Record<string, unknown>
274
- }
275
- const desktop = (pub.desktop ??= {})
276
- const userConfig = desktop[configKey]
277
-
278
- // Merge userConfig (wins) with options (defaults / inline)
279
- const merged = defu(
280
- userConfig && typeof userConfig === 'object' ? userConfig : {},
281
- options as Record<string, unknown>,
282
- )
283
-
284
- // Mutate options in place so userSetup receives the fully merged options
285
- Object.assign(options, merged)
286
-
287
- // Set/update the merged config on public.desktop
288
- desktop[configKey] = options
289
-
290
- if (typeof userSetup === 'function') {
291
- return userSetup(options, nuxt)
292
- }
293
- },
294
- } as NuxtModule)
295
- }
296
-
297
- type DesktopThemeDefinition = NuxtModule<
298
- Record<string, unknown>,
299
- Record<string, unknown>,
300
- false
301
- >
302
-
303
- /**
304
- * Nuxt module wrapper for desktop themes.
305
- * Merges theme shell defaults into `runtimeConfig.public.desktop` (user desktop.config wins).
306
- *
307
- * Tailwind content for theme Vue templates is registered via
308
- * `@owdproject/kit-primevue/kit/registerTailwindPath` after installing kit-primevue.
309
- */
310
- export function defineDesktopTheme(
311
- definition: DesktopThemeDefinition,
312
- ): ReturnType<typeof defineNuxtModule> {
313
- const userSetup = definition.setup
314
-
315
- return defineNuxtModule({
316
- ...definition,
317
- meta: {
318
- ...definition.meta,
319
- configKey: 'desktop',
320
- },
321
- async setup(options, nuxt) {
322
- const pub = (nuxt.options.runtimeConfig.public ??= {}) as {
323
- desktop?: Record<string, unknown>
324
- }
325
-
326
- // Automatically merge userConfig (pub.desktop) with theme defaults (options)
327
- pub.desktop = defu(
328
- (pub.desktop ?? {}) as Record<string, unknown>,
329
- options as Record<string, unknown>,
330
- )
331
-
332
- // Mutate options in place so userSetup receives the fully merged options
333
- Object.assign(options, pub.desktop)
334
-
335
- if (typeof userSetup === 'function') {
336
- return userSetup(options, nuxt)
337
- }
338
- },
339
- } as NuxtModule)
340
- }
@@ -1,56 +0,0 @@
1
- import { getActivePinia, setActivePinia } from 'pinia'
2
- import type { Pinia } from 'pinia'
3
- import { useApplicationManager } from '../runtime/composables/useApplicationManager'
4
-
5
- const pendingDesktopApps: ApplicationConfig[] = []
6
-
7
- let pluginPiniaInstance: Pinia | undefined
8
-
9
- /** Set by desktop-shell-init; avoids importing nuxt/app during jiti config load. */
10
- export function registerDesktopPluginPinia(pinia: Pinia | undefined) {
11
- pluginPiniaInstance = pinia
12
- }
13
-
14
- function resolveActivePinia() {
15
- const active = getActivePinia()
16
- if (active) return active
17
-
18
- if (pluginPiniaInstance) {
19
- setActivePinia(pluginPiniaInstance)
20
- return pluginPiniaInstance
21
- }
22
-
23
- return undefined
24
- }
25
-
26
- let isBooted = false
27
-
28
- /**
29
- * Register a desktop app. Queues until Pinia is active when theme/app plugins
30
- * run before shell-init (legacy published apps using synchronous setup).
31
- */
32
- export async function defineDesktopApp(config: ApplicationConfig) {
33
- if (import.meta.server) return undefined
34
-
35
- if (isBooted && resolveActivePinia()) {
36
- const applicationManager = useApplicationManager()
37
- return applicationManager.defineApp(config.id, config)
38
- }
39
-
40
- pendingDesktopApps.push(config)
41
- return undefined
42
- }
43
-
44
- export async function flushPendingDesktopApps() {
45
- isBooted = true
46
- if (pendingDesktopApps.length === 0) return
47
-
48
- if (!resolveActivePinia()) return
49
-
50
- const queue = pendingDesktopApps.splice(0, pendingDesktopApps.length)
51
- const applicationManager = useApplicationManager()
52
-
53
- for (const config of queue) {
54
- await applicationManager.defineApp(config.id, config)
55
- }
56
- }