@sprucelabs/heartwood-view-controllers 111.1.29 → 111.1.31
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/build/.spruce/errors/errors.types.d.ts +20 -0
- package/build/.spruce/errors/heartwoodViewControllers/appNotFound.schema.d.ts +3 -0
- package/build/.spruce/errors/heartwoodViewControllers/appNotFound.schema.js +19 -0
- package/build/.spruce/errors/options.types.d.ts +4 -1
- package/build/errors/SpruceError.js +3 -0
- package/build/errors/appNotFound.builder.d.ts +11 -0
- package/build/errors/appNotFound.builder.js +13 -0
- package/build/esm/.spruce/errors/errors.types.d.ts +20 -0
- package/build/esm/.spruce/errors/options.types.d.ts +4 -1
- package/build/esm/errors/SpruceError.js +3 -0
- package/build/esm/errors/appNotFound.builder.d.ts +11 -0
- package/build/esm/errors/appNotFound.builder.js +11 -0
- package/build/esm/tests/constants.d.ts +1 -0
- package/build/esm/tests/constants.js +1 -0
- package/build/esm/types/heartwood.types.d.ts +1 -1
- package/build/esm/viewControllers/Abstract.avc.d.ts +1 -0
- package/build/esm/viewControllers/Abstract.vc.d.ts +1 -0
- package/build/esm/viewControllers/ViewControllerFactory.d.ts +5 -3
- package/build/esm/viewControllers/ViewControllerFactory.js +22 -7
- package/build/tests/constants.d.ts +1 -0
- package/build/tests/constants.js +2 -1
- package/build/types/heartwood.types.d.ts +1 -1
- package/build/viewControllers/Abstract.avc.d.ts +1 -0
- package/build/viewControllers/Abstract.vc.d.ts +1 -0
- package/build/viewControllers/ViewControllerFactory.d.ts +5 -3
- package/build/viewControllers/ViewControllerFactory.js +22 -7
- package/package.json +1 -1
|
@@ -387,3 +387,23 @@ export declare namespace SpruceErrors.HeartwoodViewControllers {
|
|
|
387
387
|
}
|
|
388
388
|
type CellDeletedEntity = SchemaEntity<SpruceErrors.HeartwoodViewControllers.CellDeletedSchema>;
|
|
389
389
|
}
|
|
390
|
+
export declare namespace SpruceErrors.HeartwoodViewControllers {
|
|
391
|
+
interface AppNotFound {
|
|
392
|
+
'namespace': string;
|
|
393
|
+
}
|
|
394
|
+
interface AppNotFoundSchema extends SpruceSchema.Schema {
|
|
395
|
+
id: 'appNotFound';
|
|
396
|
+
namespace: 'HeartwoodViewControllers';
|
|
397
|
+
name: 'App not found';
|
|
398
|
+
moduleToImportFromWhenRemote: '@sprucelabs/heartwood-view-controllers';
|
|
399
|
+
fields: {
|
|
400
|
+
/** . */
|
|
401
|
+
'namespace': {
|
|
402
|
+
type: 'id';
|
|
403
|
+
isRequired: true;
|
|
404
|
+
options: undefined;
|
|
405
|
+
};
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
type AppNotFoundEntity = SchemaEntity<SpruceErrors.HeartwoodViewControllers.AppNotFoundSchema>;
|
|
409
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const schema_1 = require("@sprucelabs/schema");
|
|
4
|
+
const appNotFoundSchema = {
|
|
5
|
+
id: 'appNotFound',
|
|
6
|
+
namespace: 'HeartwoodViewControllers',
|
|
7
|
+
name: 'App not found',
|
|
8
|
+
moduleToImportFromWhenRemote: '@sprucelabs/heartwood-view-controllers',
|
|
9
|
+
fields: {
|
|
10
|
+
/** . */
|
|
11
|
+
'namespace': {
|
|
12
|
+
type: 'id',
|
|
13
|
+
isRequired: true,
|
|
14
|
+
options: undefined
|
|
15
|
+
},
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
schema_1.SchemaRegistry.getInstance().trackSchema(appNotFoundSchema);
|
|
19
|
+
exports.default = appNotFoundSchema;
|
|
@@ -57,5 +57,8 @@ export interface DateAlreadySelectedErrorOptions extends SpruceErrors.HeartwoodV
|
|
|
57
57
|
export interface CellDeletedErrorOptions extends SpruceErrors.HeartwoodViewControllers.CellDeleted, ISpruceErrorOptions {
|
|
58
58
|
code: 'CELL_DELETED';
|
|
59
59
|
}
|
|
60
|
-
|
|
60
|
+
export interface AppNotFoundErrorOptions extends SpruceErrors.HeartwoodViewControllers.AppNotFound, ISpruceErrorOptions {
|
|
61
|
+
code: 'APP_NOT_FOUND';
|
|
62
|
+
}
|
|
63
|
+
type ErrorOptions = ViewAlreadyDestroyedErrorOptions | ToolNotFoundErrorOptions | StepNotCompleteErrorOptions | SlideNotFoundErrorOptions | RowDeletedErrorOptions | PersonNotFoundErrorOptions | NoFieldVcSetErrorOptions | MissingStorageErrorOptions | InvalidViewControllerSourceErrorOptions | InvalidViewControllerNameErrorOptions | InvalidSkillViewControllerErrorOptions | ExportFailedErrorOptions | EventNotFoundErrorOptions | DuplicateToolIdErrorOptions | DuplicateRowIdErrorOptions | DuplicateEventIdErrorOptions | DateNotSelectedErrorOptions | DateAlreadySelectedErrorOptions | CellDeletedErrorOptions | AppNotFoundErrorOptions;
|
|
61
64
|
export default ErrorOptions;
|
|
@@ -74,6 +74,9 @@ class SpruceError extends error_1.default {
|
|
|
74
74
|
case 'STEP_NOT_COMPLETE':
|
|
75
75
|
message = `You tried to open step '${options.stepId}', but it's not complete!`;
|
|
76
76
|
break;
|
|
77
|
+
case 'APP_NOT_FOUND':
|
|
78
|
+
message = `I could not find an App with the namespace '${options.namespace}'!`;
|
|
79
|
+
break;
|
|
77
80
|
default:
|
|
78
81
|
message = super.friendlyMessage();
|
|
79
82
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const schema_1 = require("@sprucelabs/schema");
|
|
4
|
+
exports.default = (0, schema_1.buildErrorSchema)({
|
|
5
|
+
id: 'appNotFound',
|
|
6
|
+
name: 'App not found',
|
|
7
|
+
fields: {
|
|
8
|
+
namespace: {
|
|
9
|
+
type: 'id',
|
|
10
|
+
isRequired: true,
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
});
|
|
@@ -387,3 +387,23 @@ export declare namespace SpruceErrors.HeartwoodViewControllers {
|
|
|
387
387
|
}
|
|
388
388
|
type CellDeletedEntity = SchemaEntity<SpruceErrors.HeartwoodViewControllers.CellDeletedSchema>;
|
|
389
389
|
}
|
|
390
|
+
export declare namespace SpruceErrors.HeartwoodViewControllers {
|
|
391
|
+
interface AppNotFound {
|
|
392
|
+
'namespace': string;
|
|
393
|
+
}
|
|
394
|
+
interface AppNotFoundSchema extends SpruceSchema.Schema {
|
|
395
|
+
id: 'appNotFound';
|
|
396
|
+
namespace: 'HeartwoodViewControllers';
|
|
397
|
+
name: 'App not found';
|
|
398
|
+
moduleToImportFromWhenRemote: '@sprucelabs/heartwood-view-controllers';
|
|
399
|
+
fields: {
|
|
400
|
+
/** . */
|
|
401
|
+
'namespace': {
|
|
402
|
+
type: 'id';
|
|
403
|
+
isRequired: true;
|
|
404
|
+
options: undefined;
|
|
405
|
+
};
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
type AppNotFoundEntity = SchemaEntity<SpruceErrors.HeartwoodViewControllers.AppNotFoundSchema>;
|
|
409
|
+
}
|
|
@@ -57,5 +57,8 @@ export interface DateAlreadySelectedErrorOptions extends SpruceErrors.HeartwoodV
|
|
|
57
57
|
export interface CellDeletedErrorOptions extends SpruceErrors.HeartwoodViewControllers.CellDeleted, ISpruceErrorOptions {
|
|
58
58
|
code: 'CELL_DELETED';
|
|
59
59
|
}
|
|
60
|
-
|
|
60
|
+
export interface AppNotFoundErrorOptions extends SpruceErrors.HeartwoodViewControllers.AppNotFound, ISpruceErrorOptions {
|
|
61
|
+
code: 'APP_NOT_FOUND';
|
|
62
|
+
}
|
|
63
|
+
type ErrorOptions = ViewAlreadyDestroyedErrorOptions | ToolNotFoundErrorOptions | StepNotCompleteErrorOptions | SlideNotFoundErrorOptions | RowDeletedErrorOptions | PersonNotFoundErrorOptions | NoFieldVcSetErrorOptions | MissingStorageErrorOptions | InvalidViewControllerSourceErrorOptions | InvalidViewControllerNameErrorOptions | InvalidSkillViewControllerErrorOptions | ExportFailedErrorOptions | EventNotFoundErrorOptions | DuplicateToolIdErrorOptions | DuplicateRowIdErrorOptions | DuplicateEventIdErrorOptions | DateNotSelectedErrorOptions | DateAlreadySelectedErrorOptions | CellDeletedErrorOptions | AppNotFoundErrorOptions;
|
|
61
64
|
export default ErrorOptions;
|
|
@@ -70,6 +70,9 @@ export default class SpruceError extends AbstractSpruceError {
|
|
|
70
70
|
case 'STEP_NOT_COMPLETE':
|
|
71
71
|
message = `You tried to open step '${options.stepId}', but it's not complete!`;
|
|
72
72
|
break;
|
|
73
|
+
case 'APP_NOT_FOUND':
|
|
74
|
+
message = `I could not find an App with the namespace '${options.namespace}'!`;
|
|
75
|
+
break;
|
|
73
76
|
default:
|
|
74
77
|
message = super.friendlyMessage();
|
|
75
78
|
}
|
|
@@ -5,6 +5,7 @@ export declare const importExportCwd: string;
|
|
|
5
5
|
export declare const importExportSource: string;
|
|
6
6
|
export declare const importExportSourceNoIds: string;
|
|
7
7
|
export declare const importExportSourceApp: string;
|
|
8
|
+
export declare const importExportSourceApp2: string;
|
|
8
9
|
export declare const importExportDestinationApp: string;
|
|
9
10
|
export declare const importExportDestinationNoIds: string;
|
|
10
11
|
export declare const importExportSourceSyntaxError: string;
|
|
@@ -12,6 +12,7 @@ export const importExportSource = '.' +
|
|
|
12
12
|
diskUtil.resolvePath('src', '.spruce', 'views', 'views.ts');
|
|
13
13
|
export const importExportSourceNoIds = diskUtil.resolvePath(__dirname, '..', '..', 'src', '__tests__', 'testDirsAndFiles', 'skill_no_ids', 'src', '.spruce', 'views', 'views.ts');
|
|
14
14
|
export const importExportSourceApp = diskUtil.resolvePath(__dirname, '..', '..', 'src', '__tests__', 'testDirsAndFiles', 'skill_with_app', 'src', '.spruce', 'views', 'views.ts');
|
|
15
|
+
export const importExportSourceApp2 = diskUtil.resolvePath(__dirname, '..', '..', 'src', '__tests__', 'testDirsAndFiles', 'skill_with_app_2', 'src', '.spruce', 'views', 'views.ts');
|
|
15
16
|
export const importExportDestinationApp = diskUtil.resolvePath(diskUtil.createRandomTempDir(), 'bundle.js');
|
|
16
17
|
export const importExportDestinationNoIds = diskUtil.resolvePath(diskUtil.createRandomTempDir(), 'bundle.js');
|
|
17
18
|
export const importExportSourceSyntaxError = diskUtil.resolvePath(__dirname, '..', '..', 'src', '__tests__', 'testDirsAndFiles', 'skill_syntax_error', 'src', '.spruce', 'views', 'views.ts');
|
|
@@ -205,7 +205,7 @@ export interface SkillViewController<Args extends Record<string, any> = Record<s
|
|
|
205
205
|
getTitle?(): string | undefined;
|
|
206
206
|
getSubtitle?(): string | undefined;
|
|
207
207
|
}
|
|
208
|
-
export type ImportedViewController = (new () => ViewController<any> | SkillViewController) & {
|
|
208
|
+
export type ImportedViewController = (new (options: ViewControllerOptions) => ViewController<any> | SkillViewController) & {
|
|
209
209
|
id: string;
|
|
210
210
|
};
|
|
211
211
|
export type ViewControllerId = keyof ViewControllerMap;
|
|
@@ -4,6 +4,7 @@ import { Client, ViewController, ViewControllerOptions, ConfirmOptions, ViewCont
|
|
|
4
4
|
import { DialogViewControllerOptions } from './Dialog.vc';
|
|
5
5
|
import ViewControllerFactory from './ViewControllerFactory';
|
|
6
6
|
export default abstract class AbstractViewController<ViewModel extends Record<string, any>> implements ViewController<ViewModel> {
|
|
7
|
+
static id: string;
|
|
7
8
|
private vcFactory;
|
|
8
9
|
private renderInDialogHandler;
|
|
9
10
|
private confirmHandler;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DateUtil } from '@sprucelabs/calendar-utils';
|
|
2
2
|
import { Log } from '@sprucelabs/spruce-skill-utils';
|
|
3
|
-
import { ConfirmHandler, ControllerOptions, ImportedViewController, RenderInDialogHandler, ViewController, ViewControllerMap, ViewControllerId, VoteHandler, Device, MapUtil, ViewControllerConstructor, ToastHandler, ViewControllerPlugins, ViewControllerPluginsByName, ConnectToApi, ViewControllerPlugin, ViewControllerPluginOptions, ViewControllerOptions, AppViewController } from '../types/heartwood.types';
|
|
3
|
+
import { ConfirmHandler, ControllerOptions, ImportedViewController, RenderInDialogHandler, ViewController, ViewControllerMap, ViewControllerId, VoteHandler, Device, MapUtil, ViewControllerConstructor, ToastHandler, ViewControllerPlugins, ViewControllerPluginsByName, ConnectToApi, ViewControllerPlugin, ViewControllerPluginOptions, ViewControllerOptions, AppViewController, AppViewControllerConstructor } from '../types/heartwood.types';
|
|
4
4
|
export default class ViewControllerFactory {
|
|
5
5
|
static Class?: typeof ViewControllerFactory;
|
|
6
6
|
private controllerMap;
|
|
@@ -14,6 +14,7 @@ export default class ViewControllerFactory {
|
|
|
14
14
|
private toastHandler;
|
|
15
15
|
protected log?: Log;
|
|
16
16
|
protected plugins: ViewControllerPlugins;
|
|
17
|
+
private AppMap;
|
|
17
18
|
constructor(options: ViewControllerFactoryConstructorOptions);
|
|
18
19
|
setRenderInDialogHandler(handler: RenderInDialogHandler): void;
|
|
19
20
|
setConfirmHandler(handler: ConfirmHandler): void;
|
|
@@ -21,7 +22,7 @@ export default class ViewControllerFactory {
|
|
|
21
22
|
static Factory(options: ViewControllerFactoryOptions): ViewControllerFactory;
|
|
22
23
|
setController<Vc extends ViewController<any>>(name: string, Class: ViewControllerConstructor<Vc>): void;
|
|
23
24
|
mixinControllers(map: Record<string, ViewControllerConstructor<ViewController<any>>>): void;
|
|
24
|
-
importControllers<Vc extends ImportedViewController>(Vcs: Vc[], plugins?: ViewControllerPluginsByName): void;
|
|
25
|
+
importControllers<Vc extends ImportedViewController>(Vcs: Vc[], plugins?: ViewControllerPluginsByName, App?: AppViewControllerConstructor): void;
|
|
25
26
|
private importPlugins;
|
|
26
27
|
BuildPlugin<P extends ViewControllerPlugin>(Plugin: new (options: ViewControllerPluginOptions) => P): P;
|
|
27
28
|
BuildApp<A extends AppViewController>(App: new (options: ViewControllerOptions) => A): A;
|
|
@@ -29,7 +30,8 @@ export default class ViewControllerFactory {
|
|
|
29
30
|
getController<N extends ViewControllerId>(name: N): any;
|
|
30
31
|
setDates(dates: DateUtil): void;
|
|
31
32
|
addPlugin(named: string, plugin: ViewControllerPlugin): void;
|
|
32
|
-
|
|
33
|
+
App(namespace: string): AppViewController;
|
|
34
|
+
Controller<N extends ViewControllerId, O extends ControllerOptions<N>>(id: N, options: O): ViewControllerMap[N];
|
|
33
35
|
protected buildViewContructorOptions(name: string, options?: Record<string, any>): ViewControllerOptions;
|
|
34
36
|
private sharedConstructorOptions;
|
|
35
37
|
}
|
|
@@ -16,6 +16,7 @@ import mapUtil from '../maps/map.utility.js';
|
|
|
16
16
|
export default class ViewControllerFactory {
|
|
17
17
|
constructor(options) {
|
|
18
18
|
this.plugins = {};
|
|
19
|
+
this.AppMap = {};
|
|
19
20
|
const { controllerMap, renderInDialogHandler, confirmHandler, connectToApi, voteHandler, device, dates, maps, toastHandler, log, pluginsByName, } = options;
|
|
20
21
|
this.controllerMap = Object.assign(Object.assign({}, controllerMap), CORE_CONTROLLER_MAP);
|
|
21
22
|
this.renderInDialogHandler = renderInDialogHandler;
|
|
@@ -64,11 +65,15 @@ export default class ViewControllerFactory {
|
|
|
64
65
|
mixinControllers(map) {
|
|
65
66
|
this.controllerMap = Object.assign(Object.assign({}, this.controllerMap), map);
|
|
66
67
|
}
|
|
67
|
-
importControllers(Vcs, plugins) {
|
|
68
|
+
importControllers(Vcs, plugins, App) {
|
|
68
69
|
for (const Vc of Vcs) {
|
|
69
70
|
//@ts-ignore
|
|
70
71
|
this.controllerMap[Vc.id] = Vc;
|
|
71
72
|
}
|
|
73
|
+
if (App) {
|
|
74
|
+
//@ts-ignore
|
|
75
|
+
this.AppMap[App.id] = App;
|
|
76
|
+
}
|
|
72
77
|
this.importPlugins(plugins);
|
|
73
78
|
}
|
|
74
79
|
importPlugins(pluginsByName) {
|
|
@@ -97,16 +102,26 @@ export default class ViewControllerFactory {
|
|
|
97
102
|
//@ts-ignore
|
|
98
103
|
this.plugins[named] = plugin;
|
|
99
104
|
}
|
|
100
|
-
|
|
101
|
-
const
|
|
105
|
+
App(namespace) {
|
|
106
|
+
const App = this.AppMap[namespace];
|
|
107
|
+
if (!App) {
|
|
108
|
+
throw new SpruceError({
|
|
109
|
+
code: 'APP_NOT_FOUND',
|
|
110
|
+
namespace,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return this.BuildApp(App);
|
|
114
|
+
}
|
|
115
|
+
Controller(id, options) {
|
|
116
|
+
const Class = this.controllerMap[id];
|
|
102
117
|
if (!Class) {
|
|
103
118
|
throw new SpruceError({
|
|
104
119
|
code: 'INVALID_VIEW_CONTROLLER_NAME',
|
|
105
|
-
name,
|
|
120
|
+
name: id,
|
|
106
121
|
validNames: Object.keys(this.controllerMap),
|
|
107
122
|
});
|
|
108
123
|
}
|
|
109
|
-
const constructorOptions = this.buildViewContructorOptions(
|
|
124
|
+
const constructorOptions = this.buildViewContructorOptions(id, options);
|
|
110
125
|
const oldController = Class.prototype.Controller;
|
|
111
126
|
//@ts-ignore
|
|
112
127
|
let instance = new Class(constructorOptions);
|
|
@@ -116,11 +131,11 @@ export default class ViewControllerFactory {
|
|
|
116
131
|
throw new SpruceError({
|
|
117
132
|
code: 'INVALID_SKILL_VIEW_CONTROLLER',
|
|
118
133
|
friendlyMessage: `Property \`id\` is reserved. Please rename it to \`_id\`.`,
|
|
119
|
-
id
|
|
134
|
+
id,
|
|
120
135
|
});
|
|
121
136
|
}
|
|
122
137
|
//@ts-ignore
|
|
123
|
-
instance.id =
|
|
138
|
+
instance.id = id;
|
|
124
139
|
//@ts-ignore
|
|
125
140
|
return instance;
|
|
126
141
|
}
|
|
@@ -5,6 +5,7 @@ export declare const importExportCwd: string;
|
|
|
5
5
|
export declare const importExportSource: string;
|
|
6
6
|
export declare const importExportSourceNoIds: string;
|
|
7
7
|
export declare const importExportSourceApp: string;
|
|
8
|
+
export declare const importExportSourceApp2: string;
|
|
8
9
|
export declare const importExportDestinationApp: string;
|
|
9
10
|
export declare const importExportDestinationNoIds: string;
|
|
10
11
|
export declare const importExportSourceSyntaxError: string;
|
package/build/tests/constants.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.importExportSourcePlugins2 = exports.importExportSourcePlugins1 = exports.importExportSourceWithDefines = exports.importExportSourceNodeModulesImport = exports.buildCwdNodeModulesImport = exports.importExportDestination = exports.importExportSourceSyntaxError = exports.importExportDestinationNoIds = exports.importExportDestinationApp = exports.importExportSourceApp = exports.importExportSourceNoIds = exports.importExportSource = exports.importExportCwd = exports.DEMO_NUMBER_ACTIVE_RECORD = exports.DEMO_NUMBER2 = exports.DEMO_NUMBER = void 0;
|
|
6
|
+
exports.importExportSourcePlugins2 = exports.importExportSourcePlugins1 = exports.importExportSourceWithDefines = exports.importExportSourceNodeModulesImport = exports.buildCwdNodeModulesImport = exports.importExportDestination = exports.importExportSourceSyntaxError = exports.importExportDestinationNoIds = exports.importExportDestinationApp = exports.importExportSourceApp2 = exports.importExportSourceApp = exports.importExportSourceNoIds = exports.importExportSource = exports.importExportCwd = exports.DEMO_NUMBER_ACTIVE_RECORD = exports.DEMO_NUMBER2 = exports.DEMO_NUMBER = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils");
|
|
9
9
|
const dotenv = require('dotenv');
|
|
@@ -17,6 +17,7 @@ exports.importExportSource = '.' +
|
|
|
17
17
|
spruce_skill_utils_1.diskUtil.resolvePath('src', '.spruce', 'views', 'views.ts');
|
|
18
18
|
exports.importExportSourceNoIds = spruce_skill_utils_1.diskUtil.resolvePath(__dirname, '..', '..', 'src', '__tests__', 'testDirsAndFiles', 'skill_no_ids', 'src', '.spruce', 'views', 'views.ts');
|
|
19
19
|
exports.importExportSourceApp = spruce_skill_utils_1.diskUtil.resolvePath(__dirname, '..', '..', 'src', '__tests__', 'testDirsAndFiles', 'skill_with_app', 'src', '.spruce', 'views', 'views.ts');
|
|
20
|
+
exports.importExportSourceApp2 = spruce_skill_utils_1.diskUtil.resolvePath(__dirname, '..', '..', 'src', '__tests__', 'testDirsAndFiles', 'skill_with_app_2', 'src', '.spruce', 'views', 'views.ts');
|
|
20
21
|
exports.importExportDestinationApp = spruce_skill_utils_1.diskUtil.resolvePath(spruce_skill_utils_1.diskUtil.createRandomTempDir(), 'bundle.js');
|
|
21
22
|
exports.importExportDestinationNoIds = spruce_skill_utils_1.diskUtil.resolvePath(spruce_skill_utils_1.diskUtil.createRandomTempDir(), 'bundle.js');
|
|
22
23
|
exports.importExportSourceSyntaxError = spruce_skill_utils_1.diskUtil.resolvePath(__dirname, '..', '..', 'src', '__tests__', 'testDirsAndFiles', 'skill_syntax_error', 'src', '.spruce', 'views', 'views.ts');
|
|
@@ -205,7 +205,7 @@ export interface SkillViewController<Args extends Record<string, any> = Record<s
|
|
|
205
205
|
getTitle?(): string | undefined;
|
|
206
206
|
getSubtitle?(): string | undefined;
|
|
207
207
|
}
|
|
208
|
-
export type ImportedViewController = (new () => ViewController<any> | SkillViewController) & {
|
|
208
|
+
export type ImportedViewController = (new (options: ViewControllerOptions) => ViewController<any> | SkillViewController) & {
|
|
209
209
|
id: string;
|
|
210
210
|
};
|
|
211
211
|
export type ViewControllerId = keyof ViewControllerMap;
|
|
@@ -4,6 +4,7 @@ import { Client, ViewController, ViewControllerOptions, ConfirmOptions, ViewCont
|
|
|
4
4
|
import { DialogViewControllerOptions } from './Dialog.vc';
|
|
5
5
|
import ViewControllerFactory from './ViewControllerFactory';
|
|
6
6
|
export default abstract class AbstractViewController<ViewModel extends Record<string, any>> implements ViewController<ViewModel> {
|
|
7
|
+
static id: string;
|
|
7
8
|
private vcFactory;
|
|
8
9
|
private renderInDialogHandler;
|
|
9
10
|
private confirmHandler;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DateUtil } from '@sprucelabs/calendar-utils';
|
|
2
2
|
import { Log } from '@sprucelabs/spruce-skill-utils';
|
|
3
|
-
import { ConfirmHandler, ControllerOptions, ImportedViewController, RenderInDialogHandler, ViewController, ViewControllerMap, ViewControllerId, VoteHandler, Device, MapUtil, ViewControllerConstructor, ToastHandler, ViewControllerPlugins, ViewControllerPluginsByName, ConnectToApi, ViewControllerPlugin, ViewControllerPluginOptions, ViewControllerOptions, AppViewController } from '../types/heartwood.types';
|
|
3
|
+
import { ConfirmHandler, ControllerOptions, ImportedViewController, RenderInDialogHandler, ViewController, ViewControllerMap, ViewControllerId, VoteHandler, Device, MapUtil, ViewControllerConstructor, ToastHandler, ViewControllerPlugins, ViewControllerPluginsByName, ConnectToApi, ViewControllerPlugin, ViewControllerPluginOptions, ViewControllerOptions, AppViewController, AppViewControllerConstructor } from '../types/heartwood.types';
|
|
4
4
|
export default class ViewControllerFactory {
|
|
5
5
|
static Class?: typeof ViewControllerFactory;
|
|
6
6
|
private controllerMap;
|
|
@@ -14,6 +14,7 @@ export default class ViewControllerFactory {
|
|
|
14
14
|
private toastHandler;
|
|
15
15
|
protected log?: Log;
|
|
16
16
|
protected plugins: ViewControllerPlugins;
|
|
17
|
+
private AppMap;
|
|
17
18
|
constructor(options: ViewControllerFactoryConstructorOptions);
|
|
18
19
|
setRenderInDialogHandler(handler: RenderInDialogHandler): void;
|
|
19
20
|
setConfirmHandler(handler: ConfirmHandler): void;
|
|
@@ -21,7 +22,7 @@ export default class ViewControllerFactory {
|
|
|
21
22
|
static Factory(options: ViewControllerFactoryOptions): ViewControllerFactory;
|
|
22
23
|
setController<Vc extends ViewController<any>>(name: string, Class: ViewControllerConstructor<Vc>): void;
|
|
23
24
|
mixinControllers(map: Record<string, ViewControllerConstructor<ViewController<any>>>): void;
|
|
24
|
-
importControllers<Vc extends ImportedViewController>(Vcs: Vc[], plugins?: ViewControllerPluginsByName): void;
|
|
25
|
+
importControllers<Vc extends ImportedViewController>(Vcs: Vc[], plugins?: ViewControllerPluginsByName, App?: AppViewControllerConstructor): void;
|
|
25
26
|
private importPlugins;
|
|
26
27
|
BuildPlugin<P extends ViewControllerPlugin>(Plugin: new (options: ViewControllerPluginOptions) => P): P;
|
|
27
28
|
BuildApp<A extends AppViewController>(App: new (options: ViewControllerOptions) => A): A;
|
|
@@ -29,7 +30,8 @@ export default class ViewControllerFactory {
|
|
|
29
30
|
getController<N extends ViewControllerId>(name: N): any;
|
|
30
31
|
setDates(dates: DateUtil): void;
|
|
31
32
|
addPlugin(named: string, plugin: ViewControllerPlugin): void;
|
|
32
|
-
|
|
33
|
+
App(namespace: string): AppViewController;
|
|
34
|
+
Controller<N extends ViewControllerId, O extends ControllerOptions<N>>(id: N, options: O): ViewControllerMap[N];
|
|
33
35
|
protected buildViewContructorOptions(name: string, options?: Record<string, any>): ViewControllerOptions;
|
|
34
36
|
private sharedConstructorOptions;
|
|
35
37
|
}
|
|
@@ -12,6 +12,7 @@ const map_utility_1 = __importDefault(require("../maps/map.utility"));
|
|
|
12
12
|
class ViewControllerFactory {
|
|
13
13
|
constructor(options) {
|
|
14
14
|
this.plugins = {};
|
|
15
|
+
this.AppMap = {};
|
|
15
16
|
const { controllerMap, renderInDialogHandler, confirmHandler, connectToApi, voteHandler, device, dates, maps, toastHandler, log, pluginsByName, } = options;
|
|
16
17
|
this.controllerMap = { ...controllerMap, ...controllerMap_1.CORE_CONTROLLER_MAP };
|
|
17
18
|
this.renderInDialogHandler = renderInDialogHandler;
|
|
@@ -62,11 +63,15 @@ class ViewControllerFactory {
|
|
|
62
63
|
...map,
|
|
63
64
|
};
|
|
64
65
|
}
|
|
65
|
-
importControllers(Vcs, plugins) {
|
|
66
|
+
importControllers(Vcs, plugins, App) {
|
|
66
67
|
for (const Vc of Vcs) {
|
|
67
68
|
//@ts-ignore
|
|
68
69
|
this.controllerMap[Vc.id] = Vc;
|
|
69
70
|
}
|
|
71
|
+
if (App) {
|
|
72
|
+
//@ts-ignore
|
|
73
|
+
this.AppMap[App.id] = App;
|
|
74
|
+
}
|
|
70
75
|
this.importPlugins(plugins);
|
|
71
76
|
}
|
|
72
77
|
importPlugins(pluginsByName) {
|
|
@@ -95,16 +100,26 @@ class ViewControllerFactory {
|
|
|
95
100
|
//@ts-ignore
|
|
96
101
|
this.plugins[named] = plugin;
|
|
97
102
|
}
|
|
98
|
-
|
|
99
|
-
const
|
|
103
|
+
App(namespace) {
|
|
104
|
+
const App = this.AppMap[namespace];
|
|
105
|
+
if (!App) {
|
|
106
|
+
throw new SpruceError_1.default({
|
|
107
|
+
code: 'APP_NOT_FOUND',
|
|
108
|
+
namespace,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return this.BuildApp(App);
|
|
112
|
+
}
|
|
113
|
+
Controller(id, options) {
|
|
114
|
+
const Class = this.controllerMap[id];
|
|
100
115
|
if (!Class) {
|
|
101
116
|
throw new SpruceError_1.default({
|
|
102
117
|
code: 'INVALID_VIEW_CONTROLLER_NAME',
|
|
103
|
-
name,
|
|
118
|
+
name: id,
|
|
104
119
|
validNames: Object.keys(this.controllerMap),
|
|
105
120
|
});
|
|
106
121
|
}
|
|
107
|
-
const constructorOptions = this.buildViewContructorOptions(
|
|
122
|
+
const constructorOptions = this.buildViewContructorOptions(id, options);
|
|
108
123
|
const oldController = Class.prototype.Controller;
|
|
109
124
|
//@ts-ignore
|
|
110
125
|
let instance = new Class(constructorOptions);
|
|
@@ -114,11 +129,11 @@ class ViewControllerFactory {
|
|
|
114
129
|
throw new SpruceError_1.default({
|
|
115
130
|
code: 'INVALID_SKILL_VIEW_CONTROLLER',
|
|
116
131
|
friendlyMessage: `Property \`id\` is reserved. Please rename it to \`_id\`.`,
|
|
117
|
-
id
|
|
132
|
+
id,
|
|
118
133
|
});
|
|
119
134
|
}
|
|
120
135
|
//@ts-ignore
|
|
121
|
-
instance.id =
|
|
136
|
+
instance.id = id;
|
|
122
137
|
//@ts-ignore
|
|
123
138
|
return instance;
|
|
124
139
|
}
|
package/package.json
CHANGED