@syntrologie/runtime-sdk 0.2.21 → 1.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/CAPABILITIES.md +944 -440
- package/README.md +395 -66
- package/dist/RuntimeProvider.d.ts +51 -0
- package/dist/RuntimeProvider.js +113 -0
- package/dist/RuntimeProvider.js.map +1 -0
- package/dist/SmartCanvasApp.d.ts +16 -10
- package/dist/SmartCanvasApp.js +47 -51
- package/dist/SmartCanvasApp.js.map +1 -1
- package/dist/SmartCanvasElement.d.ts +5 -5
- package/dist/SmartCanvasElement.js +24 -14
- package/dist/SmartCanvasElement.js.map +1 -1
- package/dist/SmartCanvasPortal.d.ts +2 -2
- package/dist/SmartCanvasPortal.js +2 -2
- package/dist/SmartCanvasPortal.js.map +1 -1
- package/dist/actions/ActionEngine.d.ts +11 -0
- package/dist/actions/ActionEngine.js +272 -0
- package/dist/actions/ActionEngine.js.map +1 -0
- package/dist/actions/executors/index.d.ts +116 -0
- package/dist/actions/executors/index.js +240 -0
- package/dist/actions/executors/index.js.map +1 -0
- package/dist/actions/executors/tour.d.ts +18 -0
- package/dist/actions/executors/tour.js +332 -0
- package/dist/actions/executors/tour.js.map +1 -0
- package/dist/actions/index.d.ts +10 -0
- package/dist/actions/index.js +12 -0
- package/dist/actions/index.js.map +1 -0
- package/dist/actions/types.d.ts +399 -0
- package/dist/actions/types.js +8 -0
- package/dist/actions/types.js.map +1 -0
- package/dist/actions/validation.d.ts +14 -0
- package/dist/actions/validation.js +577 -0
- package/dist/actions/validation.js.map +1 -0
- package/dist/adaptives/adaptive-chatbot/index.js +9 -0
- package/dist/adaptives/adaptive-chatbot/index.js.map +7 -0
- package/dist/adaptives/adaptive-content/index.js +2 -0
- package/dist/adaptives/adaptive-content/index.js.map +7 -0
- package/dist/adaptives/adaptive-faq/index.js +11 -0
- package/dist/adaptives/adaptive-faq/index.js.map +7 -0
- package/dist/adaptives/adaptive-gamification/index.js +2 -0
- package/dist/adaptives/adaptive-gamification/index.js.map +7 -0
- package/dist/adaptives/adaptive-nav/index.js +11 -0
- package/dist/adaptives/adaptive-nav/index.js.map +7 -0
- package/dist/adaptives/adaptive-overlays/index.js +91 -0
- package/dist/adaptives/adaptive-overlays/index.js.map +7 -0
- package/dist/antiFlicker.js +1 -1
- package/dist/api.d.ts +40 -26
- package/dist/api.js +87 -60
- package/dist/api.js.map +1 -1
- package/dist/apps/AppContext.d.ts +31 -0
- package/dist/apps/AppContext.js +91 -0
- package/dist/apps/AppContext.js.map +1 -0
- package/dist/apps/AppLoader.d.ts +85 -0
- package/dist/apps/AppLoader.js +282 -0
- package/dist/apps/AppLoader.js.map +1 -0
- package/dist/apps/AppRegistry.d.ts +102 -0
- package/dist/apps/AppRegistry.js +317 -0
- package/dist/apps/AppRegistry.js.map +1 -0
- package/dist/apps/examples/gamification-app.example.d.ts +305 -0
- package/dist/apps/examples/gamification-app.example.js +329 -0
- package/dist/apps/examples/gamification-app.example.js.map +1 -0
- package/dist/apps/index.d.ts +14 -0
- package/dist/apps/index.js +16 -0
- package/dist/apps/index.js.map +1 -0
- package/dist/apps/types.d.ts +231 -0
- package/dist/apps/types.js +8 -0
- package/dist/apps/types.js.map +1 -0
- package/dist/blocks/data/ComparisonBlock.d.ts +1 -1
- package/dist/blocks/data/ComparisonBlock.js +40 -40
- package/dist/blocks/data/ComparisonBlock.js.map +1 -1
- package/dist/blocks/data/StatsBlock.d.ts +1 -1
- package/dist/blocks/data/StatsBlock.js +42 -44
- package/dist/blocks/data/StatsBlock.js.map +1 -1
- package/dist/blocks/data/index.d.ts +2 -2
- package/dist/blocks/data/index.js +2 -2
- package/dist/blocks/index.d.ts +5 -5
- package/dist/blocks/index.js +29 -30
- package/dist/blocks/index.js.map +1 -1
- package/dist/blocks/interactive/ChecklistBlock.d.ts +1 -1
- package/dist/blocks/interactive/ChecklistBlock.js +60 -60
- package/dist/blocks/interactive/ChecklistBlock.js.map +1 -1
- package/dist/blocks/interactive/RatingBlock.d.ts +1 -1
- package/dist/blocks/interactive/RatingBlock.js +73 -65
- package/dist/blocks/interactive/RatingBlock.js.map +1 -1
- package/dist/blocks/interactive/index.d.ts +2 -2
- package/dist/blocks/interactive/index.js +2 -2
- package/dist/blocks/notification/NotificationBlock.d.ts +2 -2
- package/dist/blocks/notification/NotificationBlock.js +68 -64
- package/dist/blocks/notification/NotificationBlock.js.map +1 -1
- package/dist/blocks/notification/index.d.ts +1 -1
- package/dist/blocks/notification/index.js +1 -1
- package/dist/bootstrap.d.ts +32 -8
- package/dist/bootstrap.js +218 -102
- package/dist/bootstrap.js.map +1 -1
- package/dist/components/ShadowCanvasOverlay.d.ts +6 -6
- package/dist/components/ShadowCanvasOverlay.js +156 -118
- package/dist/components/ShadowCanvasOverlay.js.map +1 -1
- package/dist/components/TileCard.d.ts +5 -5
- package/dist/components/TileCard.js +205 -154
- package/dist/components/TileCard.js.map +1 -1
- package/dist/components/TileWheel.d.ts +3 -3
- package/dist/components/TileWheel.js +29 -7
- package/dist/components/TileWheel.js.map +1 -1
- package/dist/config-validator.d.ts +49 -0
- package/dist/config-validator.js +173 -0
- package/dist/config-validator.js.map +1 -0
- package/dist/configFetcher.d.ts +7 -3
- package/dist/configFetcher.js +70 -29
- package/dist/configFetcher.js.map +1 -1
- package/dist/context/ContextManager.d.ts +3 -3
- package/dist/context/ContextManager.js +19 -18
- package/dist/context/ContextManager.js.map +1 -1
- package/dist/context/index.d.ts +4 -4
- package/dist/context/index.js +3 -3
- package/dist/context/schema.d.ts +9 -9
- package/dist/context/schema.js +2 -2
- package/dist/context/schema.js.map +1 -1
- package/dist/decisions/engine.d.ts +5 -5
- package/dist/decisions/engine.js +13 -13
- package/dist/decisions/engine.js.map +1 -1
- package/dist/decisions/index.d.ts +6 -6
- package/dist/decisions/index.js +5 -5
- package/dist/decisions/schema.d.ts +131 -131
- package/dist/decisions/schema.js +21 -21
- package/dist/decisions/schema.js.map +1 -1
- package/dist/decisions/strategies/rules.d.ts +1 -1
- package/dist/decisions/strategies/rules.js +24 -24
- package/dist/decisions/strategies/rules.js.map +1 -1
- package/dist/decisions/strategies/score.d.ts +1 -1
- package/dist/decisions/strategies/score.js +3 -3
- package/dist/decisions/types.d.ts +19 -19
- package/dist/earlyPatcher.d.ts +8 -20
- package/dist/earlyPatcher.js +13 -62
- package/dist/earlyPatcher.js.map +1 -1
- package/dist/editorLoader.d.ts +19 -7
- package/dist/editorLoader.js +154 -97
- package/dist/editorLoader.js.map +1 -1
- package/dist/events/EventBus.d.ts +3 -3
- package/dist/events/EventBus.js +5 -7
- package/dist/events/EventBus.js.map +1 -1
- package/dist/events/index.d.ts +6 -6
- package/dist/events/index.js +5 -5
- package/dist/events/normalizers/canvas.d.ts +2 -2
- package/dist/events/normalizers/canvas.js +3 -3
- package/dist/events/normalizers/canvas.js.map +1 -1
- package/dist/events/normalizers/posthog.d.ts +25 -1
- package/dist/events/normalizers/posthog.js +35 -27
- package/dist/events/normalizers/posthog.js.map +1 -1
- package/dist/events/schema.d.ts +13 -13
- package/dist/events/schema.js +3 -3
- package/dist/events/schema.js.map +1 -1
- package/dist/events/types.d.ts +7 -1
- package/dist/events/types.js +29 -21
- package/dist/events/types.js.map +1 -1
- package/dist/experiments/adapters/growthbook.d.ts +5 -4
- package/dist/experiments/adapters/growthbook.js +14 -6
- package/dist/experiments/adapters/growthbook.js.map +1 -1
- package/dist/experiments/index.d.ts +3 -3
- package/dist/experiments/index.js +1 -1
- package/dist/experiments/registry.d.ts +2 -2
- package/dist/experiments/registry.js +2 -2
- package/dist/experiments/types.d.ts +10 -1
- package/dist/fetchers/cdnFetcher.d.ts +1 -1
- package/dist/fetchers/cdnFetcher.js +4 -8
- package/dist/fetchers/cdnFetcher.js.map +1 -1
- package/dist/fetchers/experimentsFetcher.d.ts +25 -3
- package/dist/fetchers/experimentsFetcher.js +55 -8
- package/dist/fetchers/experimentsFetcher.js.map +1 -1
- package/dist/fetchers/index.d.ts +3 -3
- package/dist/fetchers/index.js +2 -2
- package/dist/fetchers/index.js.map +1 -1
- package/dist/fetchers/mergeConfigs.d.ts +29 -0
- package/dist/fetchers/mergeConfigs.js +38 -0
- package/dist/fetchers/mergeConfigs.js.map +1 -0
- package/dist/fetchers/registry.d.ts +1 -1
- package/dist/fetchers/registry.js +4 -4
- package/dist/fetchers/types.d.ts +1 -1
- package/dist/hooks/useCanvasOverlays.d.ts +8 -5
- package/dist/hooks/useCanvasOverlays.js +66 -17
- package/dist/hooks/useCanvasOverlays.js.map +1 -1
- package/dist/hooks/useHostPatches.d.ts +2 -2
- package/dist/hooks/useHostPatches.js +8 -8
- package/dist/hooks/useHostPatches.js.map +1 -1
- package/dist/hooks/useShadowCanvasConfig.d.ts +5 -9
- package/dist/hooks/useShadowCanvasConfig.js +7 -5
- package/dist/hooks/useShadowCanvasConfig.js.map +1 -1
- package/dist/hostPatcher/core/patcher.d.ts +1 -1
- package/dist/hostPatcher/core/patcher.js +18 -9
- package/dist/hostPatcher/core/patcher.js.map +1 -1
- package/dist/hostPatcher/core/sanitizer.js +24 -3
- package/dist/hostPatcher/core/sanitizer.js.map +1 -1
- package/dist/hostPatcher/policy/defaultPolicy.js +15 -5
- package/dist/hostPatcher/policy/defaultPolicy.js.map +1 -1
- package/dist/hostPatcher/utils/anchors.js +4 -6
- package/dist/hostPatcher/utils/anchors.js.map +1 -1
- package/dist/index.d.ts +34 -27
- package/dist/index.js +51 -24
- package/dist/index.js.map +1 -1
- package/dist/logger.d.ts +29 -0
- package/dist/logger.js +81 -0
- package/dist/logger.js.map +1 -0
- package/dist/metrics/index.d.ts +1 -1
- package/dist/metrics/index.js +1 -1
- package/dist/metrics/sessionMetrics.d.ts +1 -1
- package/dist/metrics/sessionMetrics.js +6 -6
- package/dist/overlays/fetcher.d.ts +2 -2
- package/dist/overlays/fetcher.js +13 -15
- package/dist/overlays/fetcher.js.map +1 -1
- package/dist/overlays/recipeRegistry.js +2 -2
- package/dist/overlays/recipeRegistry.js.map +1 -1
- package/dist/overlays/runtime/anchor/resolve.js +1 -1
- package/dist/overlays/runtime/anchor/resolve.js.map +1 -1
- package/dist/overlays/runtime/index.d.ts +7 -7
- package/dist/overlays/runtime/index.js +7 -7
- package/dist/overlays/runtime/overlay/highlight.js +39 -39
- package/dist/overlays/runtime/overlay/highlight.js.map +1 -1
- package/dist/overlays/runtime/overlay/modal.js +5 -5
- package/dist/overlays/runtime/overlay/modal.js.map +1 -1
- package/dist/overlays/runtime/overlay/root.js +1 -1
- package/dist/overlays/runtime/overlay/runner.js +88 -28
- package/dist/overlays/runtime/overlay/runner.js.map +1 -1
- package/dist/overlays/runtime/overlay/tooltip.d.ts +1 -1
- package/dist/overlays/runtime/overlay/tooltip.js +13 -15
- package/dist/overlays/runtime/overlay/tooltip.js.map +1 -1
- package/dist/overlays/runtime/utils/dom.js +4 -1
- package/dist/overlays/runtime/utils/dom.js.map +1 -1
- package/dist/overlays/schema.d.ts +146 -146
- package/dist/overlays/schema.js +12 -8
- package/dist/overlays/schema.js.map +1 -1
- package/dist/react.d.ts +7 -7
- package/dist/react.js +4 -4
- package/dist/react.js.map +1 -1
- package/dist/render/RenderContext.d.ts +2 -2
- package/dist/render/RenderContext.js +5 -5
- package/dist/render/RenderContext.js.map +1 -1
- package/dist/render/index.d.ts +3 -3
- package/dist/render/index.js +1 -1
- package/dist/render/types.d.ts +4 -4
- package/dist/runtime.d.ts +32 -8
- package/dist/runtime.js +109 -13
- package/dist/runtime.js.map +1 -1
- package/dist/smart-canvas.esm.js +144 -55
- package/dist/smart-canvas.esm.js.map +4 -4
- package/dist/smart-canvas.js +14688 -11455
- package/dist/smart-canvas.js.map +4 -4
- package/dist/smart-canvas.min.js +145 -55
- package/dist/smart-canvas.min.js.map +4 -4
- package/dist/state/StateStore.d.ts +1 -7
- package/dist/state/StateStore.js +15 -9
- package/dist/state/StateStore.js.map +1 -1
- package/dist/state/helpers/cooldowns.d.ts +1 -1
- package/dist/state/helpers/cooldowns.js +1 -1
- package/dist/state/helpers/dismissals.d.ts +1 -1
- package/dist/state/helpers/dismissals.js +1 -1
- package/dist/state/helpers/frequency.d.ts +1 -1
- package/dist/state/helpers/frequency.js +1 -1
- package/dist/state/index.d.ts +4 -4
- package/dist/state/index.js +3 -3
- package/dist/state/schema.d.ts +1 -1
- package/dist/state/schema.js +1 -1
- package/dist/store/example.d.ts +1 -0
- package/dist/store/example.js +43 -0
- package/dist/store/example.js.map +1 -0
- package/dist/store/mini-effector.d.ts +46 -0
- package/dist/store/mini-effector.js +88 -0
- package/dist/store/mini-effector.js.map +1 -0
- package/dist/surfaces/Surfaces.d.ts +11 -0
- package/dist/surfaces/Surfaces.js +361 -0
- package/dist/surfaces/Surfaces.js.map +1 -0
- package/dist/surfaces/index.d.ts +9 -0
- package/dist/surfaces/index.js +12 -0
- package/dist/surfaces/index.js.map +1 -0
- package/dist/surfaces/positioning.d.ts +50 -0
- package/dist/surfaces/positioning.js +228 -0
- package/dist/surfaces/positioning.js.map +1 -0
- package/dist/surfaces/types.d.ts +167 -0
- package/dist/surfaces/types.js +23 -0
- package/dist/surfaces/types.js.map +1 -0
- package/dist/telemetry/adapters/noop.d.ts +12 -0
- package/dist/telemetry/adapters/noop.js +42 -0
- package/dist/telemetry/adapters/noop.js.map +1 -0
- package/dist/telemetry/adapters/posthog.d.ts +8 -2
- package/dist/telemetry/adapters/posthog.js +36 -14
- package/dist/telemetry/adapters/posthog.js.map +1 -1
- package/dist/telemetry/index.d.ts +4 -3
- package/dist/telemetry/index.js +3 -2
- package/dist/telemetry/index.js.map +1 -1
- package/dist/telemetry/registry.d.ts +2 -9
- package/dist/telemetry/registry.js +4 -2
- package/dist/telemetry/registry.js.map +1 -1
- package/dist/telemetry/types.d.ts +1 -1
- package/dist/theme/ThemeProvider.d.ts +2 -2
- package/dist/theme/ThemeProvider.js +21 -21
- package/dist/theme/ThemeProvider.js.map +1 -1
- package/dist/theme/defaultTheme.d.ts +4 -5
- package/dist/theme/defaultTheme.js +127 -118
- package/dist/theme/defaultTheme.js.map +1 -1
- package/dist/theme/extractHostTheme.d.ts +1 -1
- package/dist/theme/extractHostTheme.js +43 -45
- package/dist/theme/extractHostTheme.js.map +1 -1
- package/dist/theme/index.d.ts +5 -5
- package/dist/theme/index.js +3 -3
- package/dist/theme/index.js.map +1 -1
- package/dist/theme/types.d.ts +2 -2
- package/dist/token.d.ts +2 -0
- package/dist/token.js +3 -6
- package/dist/token.js.map +1 -1
- package/dist/types-only.d.ts +32 -0
- package/dist/types-only.js +11 -0
- package/dist/types-only.js.map +1 -0
- package/dist/types.d.ts +89 -56
- package/dist/types.js +14 -2
- package/dist/types.js.map +1 -1
- package/dist/version.d.ts +13 -0
- package/dist/version.js +14 -0
- package/dist/version.js.map +1 -0
- package/dist/widgets/WidgetRegistry.d.ts +145 -0
- package/dist/widgets/WidgetRegistry.js +191 -0
- package/dist/widgets/WidgetRegistry.js.map +1 -0
- package/dist/widgets/index.d.ts +7 -0
- package/dist/widgets/index.js +7 -0
- package/dist/widgets/index.js.map +1 -0
- package/package.json +35 -15
- package/schema/canvas-config.schema.json +488 -254
- package/schema/runtime-context.schema.json +1 -5
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* App Registry
|
|
3
|
+
*
|
|
4
|
+
* Central registry for managing SynOS apps.
|
|
5
|
+
* Handles app registration, activation, deactivation, and lifecycle management.
|
|
6
|
+
*/
|
|
7
|
+
import { createAppContext, cleanupAppContext } from './AppContext';
|
|
8
|
+
/**
|
|
9
|
+
* App registry for managing SynOS apps.
|
|
10
|
+
*/
|
|
11
|
+
export class AppRegistry {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.apps = new Map();
|
|
14
|
+
this.eventListeners = new Set();
|
|
15
|
+
this.runtime = null;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Bind the registry to a runtime instance.
|
|
19
|
+
* Must be called before apps can be activated.
|
|
20
|
+
*/
|
|
21
|
+
bind(runtime) {
|
|
22
|
+
this.runtime = runtime;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Unbind from the current runtime.
|
|
26
|
+
* Deactivates all active apps first.
|
|
27
|
+
*/
|
|
28
|
+
async unbind() {
|
|
29
|
+
// Deactivate all active apps
|
|
30
|
+
for (const [appId, registration] of this.apps) {
|
|
31
|
+
if (registration.state === 'active') {
|
|
32
|
+
await this.deactivate(appId);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
this.runtime = null;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Register an app.
|
|
39
|
+
*
|
|
40
|
+
* Registration makes the app available but does not activate it.
|
|
41
|
+
* Call activate() to start the app's runtime extensions.
|
|
42
|
+
*/
|
|
43
|
+
register(manifest) {
|
|
44
|
+
// Validate manifest
|
|
45
|
+
if (!manifest.id || typeof manifest.id !== 'string') {
|
|
46
|
+
throw new Error("App manifest must have an 'id' property");
|
|
47
|
+
}
|
|
48
|
+
if (!manifest.version || typeof manifest.version !== 'string') {
|
|
49
|
+
throw new Error("App manifest must have a 'version' property");
|
|
50
|
+
}
|
|
51
|
+
if (!manifest.name || typeof manifest.name !== 'string') {
|
|
52
|
+
throw new Error("App manifest must have a 'name' property");
|
|
53
|
+
}
|
|
54
|
+
// Check for existing registration
|
|
55
|
+
if (this.apps.has(manifest.id)) {
|
|
56
|
+
const existing = this.apps.get(manifest.id);
|
|
57
|
+
if (existing.state === 'active') {
|
|
58
|
+
throw new Error(`Cannot re-register active app: ${manifest.id}`);
|
|
59
|
+
}
|
|
60
|
+
console.warn(`[AppRegistry] Overriding existing app registration: ${manifest.id}`);
|
|
61
|
+
}
|
|
62
|
+
// Create registration
|
|
63
|
+
const registration = {
|
|
64
|
+
manifest,
|
|
65
|
+
state: 'registered',
|
|
66
|
+
registeredAt: Date.now(),
|
|
67
|
+
};
|
|
68
|
+
this.apps.set(manifest.id, registration);
|
|
69
|
+
// Emit event
|
|
70
|
+
this.emit({
|
|
71
|
+
type: 'app:registered',
|
|
72
|
+
appId: manifest.id,
|
|
73
|
+
manifest,
|
|
74
|
+
});
|
|
75
|
+
return registration;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Activate an app.
|
|
79
|
+
*
|
|
80
|
+
* Activating an app:
|
|
81
|
+
* 1. Creates an AppContext for sandboxed runtime access
|
|
82
|
+
* 2. Registers the app's actions with ExecutorRegistry
|
|
83
|
+
* 3. Registers the app's widgets with WidgetRegistry
|
|
84
|
+
* 4. Sets up the app's event handlers
|
|
85
|
+
*/
|
|
86
|
+
async activate(appId) {
|
|
87
|
+
var _a;
|
|
88
|
+
const registration = this.apps.get(appId);
|
|
89
|
+
if (!registration) {
|
|
90
|
+
throw new Error(`App not registered: ${appId}`);
|
|
91
|
+
}
|
|
92
|
+
if (registration.state === 'active') {
|
|
93
|
+
console.warn(`[AppRegistry] App already active: ${appId}`);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (!this.runtime) {
|
|
97
|
+
throw new Error('AppRegistry not bound to a runtime. Call bind() first.');
|
|
98
|
+
}
|
|
99
|
+
// Check dependencies
|
|
100
|
+
if (registration.manifest.dependencies) {
|
|
101
|
+
for (const depId of registration.manifest.dependencies) {
|
|
102
|
+
const dep = this.apps.get(depId);
|
|
103
|
+
if (!dep || dep.state !== 'active') {
|
|
104
|
+
throw new Error(`App ${appId} depends on ${depId}, which is not active`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// Update state
|
|
109
|
+
registration.state = 'activating';
|
|
110
|
+
try {
|
|
111
|
+
// Create app context
|
|
112
|
+
const isBuiltIn = ((_a = registration.manifest.metadata) === null || _a === void 0 ? void 0 : _a.isBuiltIn) === true;
|
|
113
|
+
const context = createAppContext({
|
|
114
|
+
appId,
|
|
115
|
+
runtime: this.runtime,
|
|
116
|
+
isBuiltIn,
|
|
117
|
+
});
|
|
118
|
+
// Register runtime extensions
|
|
119
|
+
const { runtime: runtimeExtensions } = registration.manifest;
|
|
120
|
+
const cleanupFns = [];
|
|
121
|
+
if (runtimeExtensions) {
|
|
122
|
+
// Register actions
|
|
123
|
+
if (runtimeExtensions.actions) {
|
|
124
|
+
for (const actionDef of runtimeExtensions.actions) {
|
|
125
|
+
context.registerAction(actionDef);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
// Register widgets
|
|
129
|
+
if (runtimeExtensions.widgets) {
|
|
130
|
+
for (const widgetDef of runtimeExtensions.widgets) {
|
|
131
|
+
context.registerWidget(widgetDef);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// Set up event handlers
|
|
135
|
+
if (runtimeExtensions.events) {
|
|
136
|
+
for (const handler of runtimeExtensions.events) {
|
|
137
|
+
const unsubscribe = this.runtime.events.subscribe((event) => {
|
|
138
|
+
if (handler.names.includes(event.name)) {
|
|
139
|
+
const eventContext = {
|
|
140
|
+
appId,
|
|
141
|
+
state: context.state,
|
|
142
|
+
telemetry: context.telemetry,
|
|
143
|
+
surfaces: context.surfaces,
|
|
144
|
+
};
|
|
145
|
+
try {
|
|
146
|
+
handler.handler(event, eventContext);
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
console.error(`[AppRegistry] Event handler error in ${appId}:`, error);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
cleanupFns.push(unsubscribe);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
// Store cleanup function
|
|
158
|
+
registration.cleanup = async () => {
|
|
159
|
+
// Run cleanup functions
|
|
160
|
+
for (const fn of cleanupFns) {
|
|
161
|
+
try {
|
|
162
|
+
await fn();
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
console.error(`[AppRegistry] Cleanup error in ${appId}:`, error);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
// Clean up app context resources
|
|
169
|
+
cleanupAppContext(appId, this.runtime);
|
|
170
|
+
};
|
|
171
|
+
// Update state
|
|
172
|
+
registration.state = 'active';
|
|
173
|
+
registration.activatedAt = Date.now();
|
|
174
|
+
// Emit event
|
|
175
|
+
this.emit({ type: 'app:activated', appId });
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
registration.state = 'error';
|
|
179
|
+
registration.error = String(error);
|
|
180
|
+
this.emit({ type: 'app:error', appId, error: String(error) });
|
|
181
|
+
throw error;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Deactivate an app.
|
|
186
|
+
*
|
|
187
|
+
* Deactivating an app:
|
|
188
|
+
* 1. Runs the cleanup function
|
|
189
|
+
* 2. Unregisters all actions and widgets
|
|
190
|
+
* 3. Removes event handlers
|
|
191
|
+
*/
|
|
192
|
+
async deactivate(appId) {
|
|
193
|
+
var _a;
|
|
194
|
+
const registration = this.apps.get(appId);
|
|
195
|
+
if (!registration) {
|
|
196
|
+
throw new Error(`App not registered: ${appId}`);
|
|
197
|
+
}
|
|
198
|
+
if (registration.state !== 'active') {
|
|
199
|
+
console.warn(`[AppRegistry] App not active: ${appId}`);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
// Check if any active apps depend on this one
|
|
203
|
+
for (const [otherId, other] of this.apps) {
|
|
204
|
+
if (other.state === 'active' && ((_a = other.manifest.dependencies) === null || _a === void 0 ? void 0 : _a.includes(appId))) {
|
|
205
|
+
throw new Error(`Cannot deactivate ${appId}: app ${otherId} depends on it`);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
// Update state
|
|
209
|
+
registration.state = 'deactivating';
|
|
210
|
+
try {
|
|
211
|
+
// Run cleanup
|
|
212
|
+
if (registration.cleanup) {
|
|
213
|
+
await registration.cleanup();
|
|
214
|
+
registration.cleanup = undefined;
|
|
215
|
+
}
|
|
216
|
+
// Update state
|
|
217
|
+
registration.state = 'inactive';
|
|
218
|
+
// Emit event
|
|
219
|
+
this.emit({ type: 'app:deactivated', appId });
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
registration.state = 'error';
|
|
223
|
+
registration.error = String(error);
|
|
224
|
+
this.emit({ type: 'app:error', appId, error: String(error) });
|
|
225
|
+
throw error;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Unregister an app.
|
|
230
|
+
*
|
|
231
|
+
* The app must be inactive before it can be unregistered.
|
|
232
|
+
*/
|
|
233
|
+
async unregister(appId) {
|
|
234
|
+
const registration = this.apps.get(appId);
|
|
235
|
+
if (!registration) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
if (registration.state === 'active') {
|
|
239
|
+
await this.deactivate(appId);
|
|
240
|
+
}
|
|
241
|
+
this.apps.delete(appId);
|
|
242
|
+
// Emit event
|
|
243
|
+
this.emit({ type: 'app:unregistered', appId });
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Get an app registration.
|
|
247
|
+
*/
|
|
248
|
+
get(appId) {
|
|
249
|
+
return this.apps.get(appId);
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Check if an app is registered.
|
|
253
|
+
*/
|
|
254
|
+
has(appId) {
|
|
255
|
+
return this.apps.has(appId);
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Check if an app is active.
|
|
259
|
+
*/
|
|
260
|
+
isActive(appId) {
|
|
261
|
+
const registration = this.apps.get(appId);
|
|
262
|
+
return (registration === null || registration === void 0 ? void 0 : registration.state) === 'active';
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* List all registered apps.
|
|
266
|
+
*/
|
|
267
|
+
list() {
|
|
268
|
+
return Array.from(this.apps.values());
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* List all active apps.
|
|
272
|
+
*/
|
|
273
|
+
listActive() {
|
|
274
|
+
return Array.from(this.apps.values()).filter((r) => r.state === 'active');
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* List all apps with editor modules.
|
|
278
|
+
*/
|
|
279
|
+
listEditable() {
|
|
280
|
+
return Array.from(this.apps.values()).filter((r) => r.manifest.editor !== undefined);
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Subscribe to registry events.
|
|
284
|
+
*/
|
|
285
|
+
subscribe(callback) {
|
|
286
|
+
this.eventListeners.add(callback);
|
|
287
|
+
return () => {
|
|
288
|
+
this.eventListeners.delete(callback);
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Emit an event to all listeners.
|
|
293
|
+
*/
|
|
294
|
+
emit(event) {
|
|
295
|
+
for (const listener of this.eventListeners) {
|
|
296
|
+
try {
|
|
297
|
+
listener(event);
|
|
298
|
+
}
|
|
299
|
+
catch (error) {
|
|
300
|
+
console.error('[AppRegistry] Event listener error:', error);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Clean up all apps.
|
|
306
|
+
*/
|
|
307
|
+
async destroy() {
|
|
308
|
+
await this.unbind();
|
|
309
|
+
this.apps.clear();
|
|
310
|
+
this.eventListeners.clear();
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Default singleton instance of AppRegistry.
|
|
315
|
+
*/
|
|
316
|
+
export const appRegistry = new AppRegistry();
|
|
317
|
+
//# sourceMappingURL=AppRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AppRegistry.js","sourceRoot":"","sources":["../../src/apps/AppRegistry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAQnE;;GAEG;AACH,MAAM,OAAO,WAAW;IAAxB;QACU,SAAI,GAAG,IAAI,GAAG,EAA2B,CAAC;QAC1C,mBAAc,GAAG,IAAI,GAAG,EAA4B,CAAC;QACrD,YAAO,GAA8B,IAAI,CAAC;IA0UpD,CAAC;IAxUC;;;OAGG;IACH,IAAI,CAAC,OAA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CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAO;QACX,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;QACpB,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QAClB,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;IAC9B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EXAMPLE: Gamification App
|
|
3
|
+
*
|
|
4
|
+
* This file demonstrates the complete structure of a SynOS app.
|
|
5
|
+
* Apps are self-contained modules that can be loaded from CDN.
|
|
6
|
+
*
|
|
7
|
+
* An app provides:
|
|
8
|
+
* 1. Runtime extensions (actions, widgets, event handlers)
|
|
9
|
+
* 2. Config schema (Zod validation)
|
|
10
|
+
* 3. Editor component (for visual editing)
|
|
11
|
+
*
|
|
12
|
+
* This file would be bundled as a standalone module (ES or UMD)
|
|
13
|
+
* and deployed to CDN at: {cdnBase}/apps/gamification/index.js
|
|
14
|
+
*/
|
|
15
|
+
import { z } from 'zod';
|
|
16
|
+
import type { NormalizedEvent } from '../../events/types';
|
|
17
|
+
import type { AppEventContext } from '../types';
|
|
18
|
+
/**
|
|
19
|
+
* App config schema - defines what config this app expects.
|
|
20
|
+
*/
|
|
21
|
+
export declare const configSchema: z.ZodObject<{
|
|
22
|
+
badges: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
23
|
+
id: z.ZodString;
|
|
24
|
+
name: z.ZodString;
|
|
25
|
+
description: z.ZodOptional<z.ZodString>;
|
|
26
|
+
icon: z.ZodString;
|
|
27
|
+
trigger: z.ZodObject<{
|
|
28
|
+
event: z.ZodString;
|
|
29
|
+
count: z.ZodOptional<z.ZodNumber>;
|
|
30
|
+
}, "strip", z.ZodTypeAny, {
|
|
31
|
+
event: string;
|
|
32
|
+
count?: number | undefined;
|
|
33
|
+
}, {
|
|
34
|
+
event: string;
|
|
35
|
+
count?: number | undefined;
|
|
36
|
+
}>;
|
|
37
|
+
}, "strip", z.ZodTypeAny, {
|
|
38
|
+
trigger: {
|
|
39
|
+
event: string;
|
|
40
|
+
count?: number | undefined;
|
|
41
|
+
};
|
|
42
|
+
id: string;
|
|
43
|
+
name: string;
|
|
44
|
+
icon: string;
|
|
45
|
+
description?: string | undefined;
|
|
46
|
+
}, {
|
|
47
|
+
trigger: {
|
|
48
|
+
event: string;
|
|
49
|
+
count?: number | undefined;
|
|
50
|
+
};
|
|
51
|
+
id: string;
|
|
52
|
+
name: string;
|
|
53
|
+
icon: string;
|
|
54
|
+
description?: string | undefined;
|
|
55
|
+
}>, "many">>;
|
|
56
|
+
showProgress: z.ZodDefault<z.ZodBoolean>;
|
|
57
|
+
celebrationStyle: z.ZodDefault<z.ZodEnum<["confetti", "toast", "modal"]>>;
|
|
58
|
+
}, "strip", z.ZodTypeAny, {
|
|
59
|
+
badges: {
|
|
60
|
+
trigger: {
|
|
61
|
+
event: string;
|
|
62
|
+
count?: number | undefined;
|
|
63
|
+
};
|
|
64
|
+
id: string;
|
|
65
|
+
name: string;
|
|
66
|
+
icon: string;
|
|
67
|
+
description?: string | undefined;
|
|
68
|
+
}[];
|
|
69
|
+
showProgress: boolean;
|
|
70
|
+
celebrationStyle: "toast" | "modal" | "confetti";
|
|
71
|
+
}, {
|
|
72
|
+
badges?: {
|
|
73
|
+
trigger: {
|
|
74
|
+
event: string;
|
|
75
|
+
count?: number | undefined;
|
|
76
|
+
};
|
|
77
|
+
id: string;
|
|
78
|
+
name: string;
|
|
79
|
+
icon: string;
|
|
80
|
+
description?: string | undefined;
|
|
81
|
+
}[] | undefined;
|
|
82
|
+
showProgress?: boolean | undefined;
|
|
83
|
+
celebrationStyle?: "toast" | "modal" | "confetti" | undefined;
|
|
84
|
+
}>;
|
|
85
|
+
export type GamificationConfig = z.infer<typeof configSchema>;
|
|
86
|
+
/**
|
|
87
|
+
* Action: Award a badge to the user.
|
|
88
|
+
*/
|
|
89
|
+
declare const AwardBadgeSchema: z.ZodObject<{
|
|
90
|
+
kind: z.ZodLiteral<"gamification:award_badge">;
|
|
91
|
+
badgeId: z.ZodString;
|
|
92
|
+
showCelebration: z.ZodDefault<z.ZodBoolean>;
|
|
93
|
+
label: z.ZodOptional<z.ZodString>;
|
|
94
|
+
}, "strip", z.ZodTypeAny, {
|
|
95
|
+
kind: "gamification:award_badge";
|
|
96
|
+
badgeId: string;
|
|
97
|
+
showCelebration: boolean;
|
|
98
|
+
label?: string | undefined;
|
|
99
|
+
}, {
|
|
100
|
+
kind: "gamification:award_badge";
|
|
101
|
+
badgeId: string;
|
|
102
|
+
label?: string | undefined;
|
|
103
|
+
showCelebration?: boolean | undefined;
|
|
104
|
+
}>;
|
|
105
|
+
/**
|
|
106
|
+
* Action: Show the progress widget.
|
|
107
|
+
*/
|
|
108
|
+
declare const ShowProgressSchema: z.ZodObject<{
|
|
109
|
+
kind: z.ZodLiteral<"gamification:show_progress">;
|
|
110
|
+
slot: z.ZodDefault<z.ZodString>;
|
|
111
|
+
label: z.ZodOptional<z.ZodString>;
|
|
112
|
+
}, "strip", z.ZodTypeAny, {
|
|
113
|
+
kind: "gamification:show_progress";
|
|
114
|
+
slot: string;
|
|
115
|
+
label?: string | undefined;
|
|
116
|
+
}, {
|
|
117
|
+
kind: "gamification:show_progress";
|
|
118
|
+
slot?: string | undefined;
|
|
119
|
+
label?: string | undefined;
|
|
120
|
+
}>;
|
|
121
|
+
/**
|
|
122
|
+
* Award badge executor.
|
|
123
|
+
*/
|
|
124
|
+
declare function executeAwardBadge(action: z.infer<typeof AwardBadgeSchema>, context: any): Promise<{
|
|
125
|
+
cleanup: () => void;
|
|
126
|
+
}>;
|
|
127
|
+
/**
|
|
128
|
+
* Show progress executor.
|
|
129
|
+
*/
|
|
130
|
+
declare function executeShowProgress(action: z.infer<typeof ShowProgressSchema>, context: any): Promise<{
|
|
131
|
+
cleanup: () => void;
|
|
132
|
+
}>;
|
|
133
|
+
/**
|
|
134
|
+
* Props passed to the editor component.
|
|
135
|
+
*/
|
|
136
|
+
interface EditorPanelProps {
|
|
137
|
+
config: Record<string, unknown>;
|
|
138
|
+
onChange: (config: Record<string, unknown>) => void;
|
|
139
|
+
editor: {
|
|
140
|
+
setDirty: (dirty: boolean) => void;
|
|
141
|
+
navigateHome: () => Promise<boolean>;
|
|
142
|
+
save: () => Promise<void>;
|
|
143
|
+
publish: (captureScreenshot?: boolean) => Promise<void>;
|
|
144
|
+
};
|
|
145
|
+
platformClient?: unknown;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Gamification editor component.
|
|
149
|
+
*/
|
|
150
|
+
declare function GamificationEditor({ config, onChange, editor }: EditorPanelProps): import("react/jsx-runtime").JSX.Element;
|
|
151
|
+
/**
|
|
152
|
+
* The complete app manifest.
|
|
153
|
+
* This is what gets registered with the AppRegistry.
|
|
154
|
+
*/
|
|
155
|
+
export declare const manifest: {
|
|
156
|
+
id: string;
|
|
157
|
+
version: string;
|
|
158
|
+
name: string;
|
|
159
|
+
description: string;
|
|
160
|
+
runtime: {
|
|
161
|
+
actions: ({
|
|
162
|
+
kind: string;
|
|
163
|
+
schema: z.ZodObject<{
|
|
164
|
+
kind: z.ZodLiteral<"gamification:award_badge">;
|
|
165
|
+
badgeId: z.ZodString;
|
|
166
|
+
showCelebration: z.ZodDefault<z.ZodBoolean>;
|
|
167
|
+
label: z.ZodOptional<z.ZodString>;
|
|
168
|
+
}, "strip", z.ZodTypeAny, {
|
|
169
|
+
kind: "gamification:award_badge";
|
|
170
|
+
badgeId: string;
|
|
171
|
+
showCelebration: boolean;
|
|
172
|
+
label?: string | undefined;
|
|
173
|
+
}, {
|
|
174
|
+
kind: "gamification:award_badge";
|
|
175
|
+
badgeId: string;
|
|
176
|
+
label?: string | undefined;
|
|
177
|
+
showCelebration?: boolean | undefined;
|
|
178
|
+
}>;
|
|
179
|
+
executor: typeof executeAwardBadge;
|
|
180
|
+
} | {
|
|
181
|
+
kind: string;
|
|
182
|
+
schema: z.ZodObject<{
|
|
183
|
+
kind: z.ZodLiteral<"gamification:show_progress">;
|
|
184
|
+
slot: z.ZodDefault<z.ZodString>;
|
|
185
|
+
label: z.ZodOptional<z.ZodString>;
|
|
186
|
+
}, "strip", z.ZodTypeAny, {
|
|
187
|
+
kind: "gamification:show_progress";
|
|
188
|
+
slot: string;
|
|
189
|
+
label?: string | undefined;
|
|
190
|
+
}, {
|
|
191
|
+
kind: "gamification:show_progress";
|
|
192
|
+
slot?: string | undefined;
|
|
193
|
+
label?: string | undefined;
|
|
194
|
+
}>;
|
|
195
|
+
executor: typeof executeShowProgress;
|
|
196
|
+
})[];
|
|
197
|
+
widgets: ({
|
|
198
|
+
id: string;
|
|
199
|
+
component: {
|
|
200
|
+
mount(container: HTMLElement, config?: {
|
|
201
|
+
badgeId: string;
|
|
202
|
+
icon: string;
|
|
203
|
+
name: string;
|
|
204
|
+
}): () => void;
|
|
205
|
+
};
|
|
206
|
+
metadata: {
|
|
207
|
+
name: string;
|
|
208
|
+
icon: string;
|
|
209
|
+
};
|
|
210
|
+
} | {
|
|
211
|
+
id: string;
|
|
212
|
+
component: {
|
|
213
|
+
mount(container: HTMLElement, config?: {
|
|
214
|
+
progress: number;
|
|
215
|
+
total: number;
|
|
216
|
+
}): () => void;
|
|
217
|
+
};
|
|
218
|
+
metadata: {
|
|
219
|
+
name: string;
|
|
220
|
+
icon: string;
|
|
221
|
+
};
|
|
222
|
+
})[];
|
|
223
|
+
events: {
|
|
224
|
+
names: string[];
|
|
225
|
+
handler: (event: NormalizedEvent, _ctx: AppEventContext) => void;
|
|
226
|
+
}[];
|
|
227
|
+
};
|
|
228
|
+
configSchema: z.ZodObject<{
|
|
229
|
+
badges: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
230
|
+
id: z.ZodString;
|
|
231
|
+
name: z.ZodString;
|
|
232
|
+
description: z.ZodOptional<z.ZodString>;
|
|
233
|
+
icon: z.ZodString;
|
|
234
|
+
trigger: z.ZodObject<{
|
|
235
|
+
event: z.ZodString;
|
|
236
|
+
count: z.ZodOptional<z.ZodNumber>;
|
|
237
|
+
}, "strip", z.ZodTypeAny, {
|
|
238
|
+
event: string;
|
|
239
|
+
count?: number | undefined;
|
|
240
|
+
}, {
|
|
241
|
+
event: string;
|
|
242
|
+
count?: number | undefined;
|
|
243
|
+
}>;
|
|
244
|
+
}, "strip", z.ZodTypeAny, {
|
|
245
|
+
trigger: {
|
|
246
|
+
event: string;
|
|
247
|
+
count?: number | undefined;
|
|
248
|
+
};
|
|
249
|
+
id: string;
|
|
250
|
+
name: string;
|
|
251
|
+
icon: string;
|
|
252
|
+
description?: string | undefined;
|
|
253
|
+
}, {
|
|
254
|
+
trigger: {
|
|
255
|
+
event: string;
|
|
256
|
+
count?: number | undefined;
|
|
257
|
+
};
|
|
258
|
+
id: string;
|
|
259
|
+
name: string;
|
|
260
|
+
icon: string;
|
|
261
|
+
description?: string | undefined;
|
|
262
|
+
}>, "many">>;
|
|
263
|
+
showProgress: z.ZodDefault<z.ZodBoolean>;
|
|
264
|
+
celebrationStyle: z.ZodDefault<z.ZodEnum<["confetti", "toast", "modal"]>>;
|
|
265
|
+
}, "strip", z.ZodTypeAny, {
|
|
266
|
+
badges: {
|
|
267
|
+
trigger: {
|
|
268
|
+
event: string;
|
|
269
|
+
count?: number | undefined;
|
|
270
|
+
};
|
|
271
|
+
id: string;
|
|
272
|
+
name: string;
|
|
273
|
+
icon: string;
|
|
274
|
+
description?: string | undefined;
|
|
275
|
+
}[];
|
|
276
|
+
showProgress: boolean;
|
|
277
|
+
celebrationStyle: "toast" | "modal" | "confetti";
|
|
278
|
+
}, {
|
|
279
|
+
badges?: {
|
|
280
|
+
trigger: {
|
|
281
|
+
event: string;
|
|
282
|
+
count?: number | undefined;
|
|
283
|
+
};
|
|
284
|
+
id: string;
|
|
285
|
+
name: string;
|
|
286
|
+
icon: string;
|
|
287
|
+
description?: string | undefined;
|
|
288
|
+
}[] | undefined;
|
|
289
|
+
showProgress?: boolean | undefined;
|
|
290
|
+
celebrationStyle?: "toast" | "modal" | "confetti" | undefined;
|
|
291
|
+
}>;
|
|
292
|
+
editor: {
|
|
293
|
+
component: typeof GamificationEditor;
|
|
294
|
+
panel: {
|
|
295
|
+
title: string;
|
|
296
|
+
icon: string;
|
|
297
|
+
description: string;
|
|
298
|
+
};
|
|
299
|
+
};
|
|
300
|
+
metadata: {
|
|
301
|
+
author: string;
|
|
302
|
+
tags: string[];
|
|
303
|
+
};
|
|
304
|
+
};
|
|
305
|
+
export default manifest;
|