@celljs/widget 4.2.0 → 4.4.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/README.md +17 -1
- package/cell.schema.json +25 -0
- package/esm/browser/annotation/widget.js +2 -1
- package/esm/browser/annotation/widget.js.map +1 -1
- package/esm/browser/locale/locale-manager.js +1 -1
- package/esm/browser/locale/locale-manager.js.map +1 -1
- package/esm/browser/theme/theme-manager.d.ts +4 -0
- package/esm/browser/theme/theme-manager.js +20 -16
- package/esm/browser/theme/theme-manager.js.map +1 -1
- package/esm/browser/widget/widget-factory.d.ts +1 -0
- package/esm/browser/widget/widget-factory.js +5 -5
- package/esm/browser/widget/widget-factory.js.map +1 -1
- package/esm/browser/widget/widget-manager.js +4 -3
- package/esm/browser/widget/widget-manager.js.map +1 -1
- package/esm/browser/widget/widget-protocol.d.ts +2 -0
- package/esm/browser/widget/widget-util.d.ts +5 -0
- package/esm/browser/widget/widget-util.js +23 -4
- package/esm/browser/widget/widget-util.js.map +1 -1
- package/lib/browser/annotation/widget.d.ts.map +1 -1
- package/lib/browser/annotation/widget.js +2 -1
- package/lib/browser/annotation/widget.js.map +1 -1
- package/lib/browser/locale/locale-manager.js +1 -1
- package/lib/browser/locale/locale-manager.js.map +1 -1
- package/lib/browser/theme/theme-manager.d.ts +4 -0
- package/lib/browser/theme/theme-manager.d.ts.map +1 -1
- package/lib/browser/theme/theme-manager.js +20 -16
- package/lib/browser/theme/theme-manager.js.map +1 -1
- package/lib/browser/theme/theme-manager.spec.d.ts +2 -0
- package/lib/browser/theme/theme-manager.spec.d.ts.map +1 -0
- package/lib/browser/theme/theme-manager.spec.js +46 -0
- package/lib/browser/theme/theme-manager.spec.js.map +1 -0
- package/lib/browser/widget/widget-factory.d.ts +1 -0
- package/lib/browser/widget/widget-factory.d.ts.map +1 -1
- package/lib/browser/widget/widget-factory.js +5 -5
- package/lib/browser/widget/widget-factory.js.map +1 -1
- package/lib/browser/widget/widget-manager.d.ts.map +1 -1
- package/lib/browser/widget/widget-manager.js +4 -3
- package/lib/browser/widget/widget-manager.js.map +1 -1
- package/lib/browser/widget/widget-protocol.d.ts +2 -0
- package/lib/browser/widget/widget-protocol.d.ts.map +1 -1
- package/lib/browser/widget/widget-util.d.ts +5 -0
- package/lib/browser/widget/widget-util.d.ts.map +1 -1
- package/lib/browser/widget/widget-util.js +23 -4
- package/lib/browser/widget/widget-util.js.map +1 -1
- package/lib/browser/widget/widget.spec.d.ts +20 -0
- package/lib/browser/widget/widget.spec.d.ts.map +1 -0
- package/lib/browser/widget/widget.spec.js +117 -0
- package/lib/browser/widget/widget.spec.js.map +1 -0
- package/package.json +4 -3
- package/src/browser/annotation/widget.ts +2 -1
- package/src/browser/locale/locale-manager.ts +1 -1
- package/src/browser/theme/theme-manager.spec.ts +48 -0
- package/src/browser/theme/theme-manager.ts +18 -14
- package/src/browser/widget/widget-factory.ts +7 -5
- package/src/browser/widget/widget-manager.ts +3 -3
- package/src/browser/widget/widget-protocol.ts +2 -0
- package/src/browser/widget/widget-util.ts +23 -6
- package/src/browser/widget/widget.spec.ts +97 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"widget-manager.js","sourceRoot":"","sources":["../../../src/browser/widget/widget-manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uCAAqF;AACrF,uDAAuE;AACvE,+CAA2C;AAGpC,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAI1B,YACsD,OAAoB,EACf,YAA2B,
|
|
1
|
+
{"version":3,"file":"widget-manager.js","sourceRoot":"","sources":["../../../src/browser/widget/widget-manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uCAAqF;AACrF,uDAAuE;AACvE,+CAA2C;AAGpC,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAI1B,YACsD,OAAoB,EACf,YAA2B,EACtC,qBAAoD;uBAF9C,OAAO;4BACF,YAAY;qCACvB,qBAAqB;IAClE,CAAC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OAAO,EAAE,EAAE,CAAC;gBACvC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,qBAAc,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;YAC1E,CAAC;YACD,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC;QAC9B,CAAC;QACD,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;IAC5C,CAAC;CAEJ,CAAA;;4BA1DY,iBAAiB;IAD7B,IAAA,gBAAS,EAAC,+BAAa,CAAC;IAMhB,WAAA,IAAA,gBAAS,EAAC,wBAAM,CAAC,CAAA;IAAE,WAAA,IAAA,eAAQ,GAAE,CAAA;IAC7B,WAAA,IAAA,gBAAS,EAAC,6BAAW,CAAC,CAAA;IAAE,WAAA,IAAA,eAAQ,GAAE,CAAA;IAClC,WAAA,IAAA,YAAK,EAAC,gBAAgB,CAAC,CAAA;;GAPnB,iBAAiB,CA0D7B"}
|
|
@@ -28,6 +28,8 @@ export interface WidgetModel {
|
|
|
28
28
|
}
|
|
29
29
|
export interface WidgetFactory<T> {
|
|
30
30
|
priority: number;
|
|
31
|
+
/** The {@link WidgetModel.type} this factory renders. */
|
|
32
|
+
readonly type: string;
|
|
31
33
|
create(widgetModel: WidgetModel): Promise<Widget<T>>;
|
|
32
34
|
support(widgetModel: WidgetModel): Promise<boolean>;
|
|
33
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"widget-protocol.d.ts","sourceRoot":"","sources":["../../../src/browser/widget/widget-protocol.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM,eAAmB,CAAC;AACvC,eAAO,MAAM,WAAW,eAAwB,CAAC;AACjD,eAAO,MAAM,aAAa,eAA0B,CAAC;AACrD,eAAO,MAAM,aAAa,eAA0B,CAAC;AAErD,oBAAY,UAAU;IAClB,SAAS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AC,EAAE,CAAC,CAAC;CACtC"}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { WidgetModel, Widget } from './widget-protocol';
|
|
2
2
|
export declare namespace WidgetUtil {
|
|
3
3
|
function create<T>(widgetModel: WidgetModel): Promise<Widget<T>>;
|
|
4
|
+
/**
|
|
5
|
+
* Copies the plain objects and arrays of widget props; anything else (components, functions,
|
|
6
|
+
* class instances) is kept as is.
|
|
7
|
+
*/
|
|
8
|
+
function copyProps<P>(props: P): P;
|
|
4
9
|
function render<T>(widgetModel: WidgetModel): Promise<T>;
|
|
5
10
|
}
|
|
6
11
|
//# sourceMappingURL=widget-util.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"widget-util.d.ts","sourceRoot":"","sources":["../../../src/browser/widget/widget-util.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAiB,MAAM,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"widget-util.d.ts","sourceRoot":"","sources":["../../../src/browser/widget/widget-util.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAiB,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEvE,yBAAiB,UAAU,CAAC;IACxB,SAAsB,MAAM,CAAC,CAAC,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAU5E;IAED;;;OAGG;IACH,SAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAexC;IAED,SAAsB,MAAM,CAAC,CAAC,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAGpE;CAEJ"}
|
|
@@ -3,13 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.WidgetUtil = void 0;
|
|
4
4
|
const core_1 = require("@celljs/core");
|
|
5
5
|
const widget_protocol_1 = require("./widget-protocol");
|
|
6
|
-
let widgetFactories;
|
|
7
6
|
var WidgetUtil;
|
|
8
7
|
(function (WidgetUtil) {
|
|
9
8
|
async function create(widgetModel) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
9
|
+
// Looked up every time, not cached: a new container (tests, HMR) brings new factories.
|
|
10
|
+
const widgetFactories = core_1.Prioritizeable.prioritizeAllSync(core_1.ContainerUtil.getAll(widget_protocol_1.WidgetFactory)).map(p => p.value);
|
|
13
11
|
for (const factory of widgetFactories) {
|
|
14
12
|
if (await factory.support(widgetModel)) {
|
|
15
13
|
const widget = await factory.create(widgetModel);
|
|
@@ -19,6 +17,27 @@ var WidgetUtil;
|
|
|
19
17
|
throw new Error(`WidgetModel {id: ${widgetModel.id}, type: ${widgetModel.type}} there is no matching widget factory.`);
|
|
20
18
|
}
|
|
21
19
|
WidgetUtil.create = create;
|
|
20
|
+
/**
|
|
21
|
+
* Copies the plain objects and arrays of widget props; anything else (components, functions,
|
|
22
|
+
* class instances) is kept as is.
|
|
23
|
+
*/
|
|
24
|
+
function copyProps(props) {
|
|
25
|
+
if (Array.isArray(props)) {
|
|
26
|
+
return props.map(copyProps);
|
|
27
|
+
}
|
|
28
|
+
if (props && typeof props === 'object') {
|
|
29
|
+
const proto = Object.getPrototypeOf(props);
|
|
30
|
+
if (proto === Object.prototype || proto === null) {
|
|
31
|
+
const copy = {};
|
|
32
|
+
for (const [key, value] of Object.entries(props)) {
|
|
33
|
+
copy[key] = copyProps(value);
|
|
34
|
+
}
|
|
35
|
+
return copy;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return props;
|
|
39
|
+
}
|
|
40
|
+
WidgetUtil.copyProps = copyProps;
|
|
22
41
|
async function render(widgetModel) {
|
|
23
42
|
const widget = await WidgetUtil.create(widgetModel);
|
|
24
43
|
return widget.render();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"widget-util.js","sourceRoot":"","sources":["../../../src/browser/widget/widget-util.ts"],"names":[],"mappings":";;;AAA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K,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;oBAC/C,IAAI,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;gBACjC,CAAC;gBACD,OAAO,IAAS,CAAC;YACrB,CAAC;QACL,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;IAfe,WAAA,SAAS,YAexB,CAAA;IAEM,KAAK,UAAU,MAAM,CAAI,WAAwB;QACpD,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,MAAM,CAAI,WAAW,CAAC,CAAC;QACvD,OAAO,MAAM,CAAC,MAAM,EAAE,CAAC;IAC3B,CAAC;IAHqB,WAAA,MAAM,SAG3B,CAAA;AAEL,CAAC,EAvCgB,UAAU,aAAV,UAAU,GAAV,UAAU,QAuC1B"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AbstractWidgetFactory } from './widget-factory';
|
|
2
|
+
import { WidgetModel } from './widget-protocol';
|
|
3
|
+
import './widget-manager';
|
|
4
|
+
/** Production builds minify class names, so a factory must not be matched by its name. */
|
|
5
|
+
export declare class Qn extends AbstractWidgetFactory<string> {
|
|
6
|
+
readonly type = "Text";
|
|
7
|
+
protected doRender(model: WidgetModel): Promise<string>;
|
|
8
|
+
}
|
|
9
|
+
/** What @celljs/react does for @Widget: render the component of the model. */
|
|
10
|
+
export declare class ComponentFactory extends AbstractWidgetFactory<string> {
|
|
11
|
+
readonly type: string;
|
|
12
|
+
protected doRender(model: WidgetModel): Promise<string>;
|
|
13
|
+
}
|
|
14
|
+
export declare class CopyrightWidget {
|
|
15
|
+
}
|
|
16
|
+
export declare class LogoWidget {
|
|
17
|
+
}
|
|
18
|
+
export declare class BannerWidget {
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=widget.spec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widget.spec.d.ts","sourceRoot":"","sources":["../../../src/browser/widget/widget.spec.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAwC,WAAW,EAAc,MAAM,mBAAmB,CAAC;AAElG,OAAO,kBAAkB,CAAC;AAE1B,0FAA0F;AAC1F,qBACa,EAAG,SAAQ,qBAAqB,CAAC,MAAM,CAAC;IACjD,QAAQ,CAAC,IAAI,UAAU;IAEvB,UAAgB,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAE5D;CACJ;AAED,8EAA8E;AAC9E,qBACa,gBAAiB,SAAQ,qBAAqB,CAAC,MAAM,CAAC;IAC/D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAwB;IAE7C,UAAgB,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAE5D;CACJ;AAED,qBACa,eAAe;CAAG;AAE/B,qBACa,UAAU;CAAG;AAE1B,qBACa,YAAY;CAAG"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.BannerWidget = exports.LogoWidget = exports.CopyrightWidget = exports.ComponentFactory = exports.Qn = void 0;
|
|
10
|
+
const bun_test_1 = require("bun:test");
|
|
11
|
+
const core_1 = require("@celljs/core");
|
|
12
|
+
const application_factory_1 = require("@celljs/core/lib/common/application/application-factory");
|
|
13
|
+
const annotation_1 = require("../annotation");
|
|
14
|
+
const widget_factory_1 = require("./widget-factory");
|
|
15
|
+
const widget_protocol_1 = require("./widget-protocol");
|
|
16
|
+
const widget_util_1 = require("./widget-util");
|
|
17
|
+
require("./widget-manager");
|
|
18
|
+
/** Production builds minify class names, so a factory must not be matched by its name. */
|
|
19
|
+
let Qn = class Qn extends widget_factory_1.AbstractWidgetFactory {
|
|
20
|
+
constructor() {
|
|
21
|
+
super(...arguments);
|
|
22
|
+
this.type = 'Text';
|
|
23
|
+
}
|
|
24
|
+
async doRender(model) {
|
|
25
|
+
var _a;
|
|
26
|
+
var _b;
|
|
27
|
+
return `${model.id}:${(_b = (_a = model.props) === null || _a === void 0 ? void 0 : _a.text) !== null && _b !== void 0 ? _b : ''}`;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
exports.Qn = Qn;
|
|
31
|
+
exports.Qn = Qn = __decorate([
|
|
32
|
+
(0, core_1.Component)(widget_protocol_1.WidgetFactory)
|
|
33
|
+
], Qn);
|
|
34
|
+
/** What @celljs/react does for @Widget: render the component of the model. */
|
|
35
|
+
let ComponentFactory = class ComponentFactory extends widget_factory_1.AbstractWidgetFactory {
|
|
36
|
+
constructor() {
|
|
37
|
+
super(...arguments);
|
|
38
|
+
this.type = widget_protocol_1.WidgetType.Decorator;
|
|
39
|
+
}
|
|
40
|
+
async doRender(model) {
|
|
41
|
+
return model.matedata.component();
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
exports.ComponentFactory = ComponentFactory;
|
|
45
|
+
exports.ComponentFactory = ComponentFactory = __decorate([
|
|
46
|
+
(0, core_1.Component)(widget_protocol_1.WidgetFactory)
|
|
47
|
+
], ComponentFactory);
|
|
48
|
+
let CopyrightWidget = class CopyrightWidget {
|
|
49
|
+
};
|
|
50
|
+
exports.CopyrightWidget = CopyrightWidget;
|
|
51
|
+
exports.CopyrightWidget = CopyrightWidget = __decorate([
|
|
52
|
+
(0, annotation_1.Widget)({ id: 'copyright', area: 'footer', priority: 10, component: () => '(c)' })
|
|
53
|
+
], CopyrightWidget);
|
|
54
|
+
let LogoWidget = class LogoWidget {
|
|
55
|
+
};
|
|
56
|
+
exports.LogoWidget = LogoWidget;
|
|
57
|
+
exports.LogoWidget = LogoWidget = __decorate([
|
|
58
|
+
(0, annotation_1.Widget)({ area: 'aside', component: () => 'logo' })
|
|
59
|
+
], LogoWidget);
|
|
60
|
+
let BannerWidget = class BannerWidget {
|
|
61
|
+
};
|
|
62
|
+
exports.BannerWidget = BannerWidget;
|
|
63
|
+
exports.BannerWidget = BannerWidget = __decorate([
|
|
64
|
+
(0, core_1.Constant)(widget_protocol_1.Widget, { id: 'banner', area: 'header', priority: 900, visible: true, render: async () => 'banner' })
|
|
65
|
+
], BannerWidget);
|
|
66
|
+
// autoBind() takes what was registered since the previous call: one module for every test.
|
|
67
|
+
const widgetModule = (0, core_1.autoBind)();
|
|
68
|
+
const boot = (widgets = {}) => application_factory_1.ApplicationFactory.create({ app: { name: 'Cell' }, widget: { widgets } }, widgetModule);
|
|
69
|
+
const manager = () => core_1.ContainerUtil.get(widget_protocol_1.WidgetManager);
|
|
70
|
+
(0, bun_test_1.describe)('@celljs/widget', () => {
|
|
71
|
+
(0, bun_test_1.it)('matches a factory by its type, not by its class name', async () => {
|
|
72
|
+
await boot({ hello: { type: 'Text', area: 'header', props: { text: 'hi' } } });
|
|
73
|
+
(0, bun_test_1.expect)(await manager().render('header')).toEqual(['banner', 'hello:hi']);
|
|
74
|
+
});
|
|
75
|
+
(0, bun_test_1.it)('a widget without configuration keeps its area; configuration without an area only changes the rest', async () => {
|
|
76
|
+
await boot({ banner: { priority: 1 } });
|
|
77
|
+
(0, bun_test_1.expect)(await manager().render('header')).toEqual(['banner']);
|
|
78
|
+
const [banner] = await manager().get('header');
|
|
79
|
+
(0, bun_test_1.expect)(banner.priority).toBe(1);
|
|
80
|
+
});
|
|
81
|
+
(0, bun_test_1.it)('configuration hides a widget and moves another to an area', async () => {
|
|
82
|
+
await boot({ banner: { visible: false }, hello: { type: 'Text', area: 'footer', priority: 1 } });
|
|
83
|
+
(0, bun_test_1.expect)(await manager().render('header')).toEqual([]);
|
|
84
|
+
(0, bun_test_1.expect)((await manager().get('footer')).map(w => w.id)).toEqual(['copyright', 'hello']);
|
|
85
|
+
(0, bun_test_1.expect)(await manager().render('footer')).toEqual(['(c)', 'hello:']);
|
|
86
|
+
});
|
|
87
|
+
(0, bun_test_1.it)('the id of a @Widget defaults to the name of the decorated class', async () => {
|
|
88
|
+
await boot();
|
|
89
|
+
(0, bun_test_1.expect)((await manager().get('aside')).map(w => w.id)).toEqual(['LogoWidget']);
|
|
90
|
+
});
|
|
91
|
+
(0, bun_test_1.it)('evaluates ${...} in props on a copy, on every render', async () => {
|
|
92
|
+
await boot();
|
|
93
|
+
const model = { id: 'w', type: 'Text', priority: 1, visible: true, props: { text: 'by ${app.name}', nested: ['${app.name}'] } };
|
|
94
|
+
const widget = await widget_util_1.WidgetUtil.create(model);
|
|
95
|
+
(0, bun_test_1.expect)(await widget.render()).toBe('w:by Cell');
|
|
96
|
+
(0, bun_test_1.expect)(await widget.render()).toBe('w:by Cell');
|
|
97
|
+
(0, bun_test_1.expect)(model.props).toEqual({ text: 'by ${app.name}', nested: ['${app.name}'] });
|
|
98
|
+
});
|
|
99
|
+
(0, bun_test_1.it)('fails with the widget id when no factory supports its type', async () => {
|
|
100
|
+
await boot();
|
|
101
|
+
await (0, bun_test_1.expect)(widget_util_1.WidgetUtil.create({ id: 'x', type: 'Unknown', priority: 1, visible: true })).rejects.toThrow('id: x');
|
|
102
|
+
});
|
|
103
|
+
(0, bun_test_1.it)('copyProps copies plain objects and arrays, keeps the rest', () => {
|
|
104
|
+
class Model {
|
|
105
|
+
}
|
|
106
|
+
const fn = () => undefined;
|
|
107
|
+
const instance = new Model();
|
|
108
|
+
const props = { a: { b: [1, { c: 2 }] }, fn, instance };
|
|
109
|
+
const copy = widget_util_1.WidgetUtil.copyProps(props);
|
|
110
|
+
(0, bun_test_1.expect)(copy).toEqual(props);
|
|
111
|
+
(0, bun_test_1.expect)(copy.a).not.toBe(props.a);
|
|
112
|
+
(0, bun_test_1.expect)(copy.a.b[1]).not.toBe(props.a.b[1]);
|
|
113
|
+
(0, bun_test_1.expect)(copy.fn).toBe(fn);
|
|
114
|
+
(0, bun_test_1.expect)(copy.instance).toBe(instance);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
//# sourceMappingURL=widget.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widget.spec.js","sourceRoot":"","sources":["../../../src/browser/widget/widget.spec.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uCAAgD;AAChD,uCAA4E;AAC5E,iGAA6F;AAC7F,8CAA0D;AAC1D,qDAAyD;AACzD,uDAAkG;AAClG,+CAA2C;AAC3C,4BAA0B;AAE1B,0FAA0F;AAEnF,IAAM,EAAE,GAAR,MAAM,EAAG,SAAQ,sCAA6B;IAA9C;;QACM,SAAI,GAAG,MAAM,CAAC;IAK3B,CAAC;IAHa,KAAK,CAAC,QAAQ,CAAC,KAAkB;;;QACvC,OAAO,GAAG,KAAK,CAAC,EAAE,IAAI,MAAA,MAAA,KAAK,CAAC,KAAK,0CAAE,IAAI,mCAAI,EAAE,EAAE,CAAC;IACpD,CAAC;CACJ,CAAA;;aANY,EAAE;IADd,IAAA,gBAAS,EAAC,+BAAa,CAAC;GACZ,EAAE,CAMd;AAED,8EAA8E;AAEvE,IAAM,gBAAgB,GAAtB,MAAM,gBAAiB,SAAQ,sCAA6B;IAA5D;;QACM,SAAI,GAAW,4BAAU,CAAC,SAAS,CAAC;IAKjD,CAAC;IAHa,KAAK,CAAC,QAAQ,CAAC,KAAkB;QACvC,OAAO,KAAK,CAAC,QAAS,CAAC,SAAS,EAAE,CAAC;IACvC,CAAC;CACJ,CAAA;;2BANY,gBA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CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC3C,IAAA,iBAAM,EAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACzB,IAAA,iBAAM,EAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/widget",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cell-component"
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
"files": [
|
|
23
23
|
"lib",
|
|
24
24
|
"esm",
|
|
25
|
-
"src"
|
|
25
|
+
"src",
|
|
26
|
+
"cell.schema.json"
|
|
26
27
|
],
|
|
27
28
|
"scripts": {
|
|
28
29
|
"build": "tsc -b && bun ../../scripts/build-esm.ts",
|
|
@@ -31,7 +32,7 @@
|
|
|
31
32
|
"watch": "tsc -b -w --preserveWatchOutput"
|
|
32
33
|
},
|
|
33
34
|
"dependencies": {
|
|
34
|
-
"@celljs/core": "4.
|
|
35
|
+
"@celljs/core": "4.4.0",
|
|
35
36
|
"rxjs": "^6.6.0",
|
|
36
37
|
"tslib": "^2.8.0"
|
|
37
38
|
},
|
|
@@ -21,7 +21,8 @@ export const Widget =
|
|
|
21
21
|
const id = widgetOption.id ? (Array.isArray(widgetOption.id) ? widgetOption.id : [ widgetOption.id ]) : [];
|
|
22
22
|
const component = widgetOption.component || t;
|
|
23
23
|
Constant([...id, component, WidgetModel], {
|
|
24
|
-
|
|
24
|
+
// The decorated class, whose name `cell build` keeps; a function component's name is minified.
|
|
25
|
+
id: widgetOption.id ? widgetOption.id.toString() : t.name,
|
|
25
26
|
visible: true,
|
|
26
27
|
type: WidgetType.Decorator,
|
|
27
28
|
priority: widgetOption.priority || 500,
|
|
@@ -7,7 +7,7 @@ export class LocaleManagerImpl implements LocaleManager {
|
|
|
7
7
|
|
|
8
8
|
protected readonly langStorageKey = 'cell:lang';
|
|
9
9
|
|
|
10
|
-
@Value('
|
|
10
|
+
@Value('widget.locales')
|
|
11
11
|
protected readonly localesForConfig: { [lang: string]: Locale };
|
|
12
12
|
|
|
13
13
|
@Autowired(Locale) @Optional()
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from 'bun:test';
|
|
2
|
+
import { autoBind, ContainerUtil } from '@celljs/core';
|
|
3
|
+
import { ApplicationFactory } from '@celljs/core/lib/common/application/application-factory';
|
|
4
|
+
import { Theme, ThemeManager } from './theme-protocol';
|
|
5
|
+
import './theme-manager';
|
|
6
|
+
|
|
7
|
+
const storage = new Map<string, string>();
|
|
8
|
+
(globalThis as any).localStorage = {
|
|
9
|
+
getItem: (key: string) => storage.get(key) ?? null,
|
|
10
|
+
setItem: (key: string, value: string) => storage.set(key, value),
|
|
11
|
+
removeItem: (key: string) => storage.delete(key),
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const themes = { light: { label: 'Light', color: '#fff', priority: 2 }, default: { label: 'Default', color: '#eee', priority: 1 }, dark: { label: 'Dark', color: '#000', priority: 3 } };
|
|
15
|
+
// autoBind() takes what was registered since the previous call: one module for every test.
|
|
16
|
+
const themeModule = autoBind();
|
|
17
|
+
const tick = () => new Promise(resolve => setTimeout(resolve));
|
|
18
|
+
|
|
19
|
+
async function current(): Promise<{ manager: ThemeManager<unknown>, theme?: Theme<unknown> }> {
|
|
20
|
+
await ApplicationFactory.create({ widget: { themes } }, themeModule);
|
|
21
|
+
const manager = ContainerUtil.get<ThemeManager<unknown>>(ThemeManager);
|
|
22
|
+
await tick();
|
|
23
|
+
return { manager, theme: manager.currentSubject.value };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
describe('ThemeManager', () => {
|
|
27
|
+
|
|
28
|
+
beforeEach(() => storage.clear());
|
|
29
|
+
|
|
30
|
+
it('selects the theme saved by its id', async () => {
|
|
31
|
+
storage.set('cell:theme', 'dark');
|
|
32
|
+
expect((await current()).theme?.label).toBe('Dark');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('selects default when nothing (or an unknown or old JSON value) is saved', async () => {
|
|
36
|
+
expect((await current()).theme?.id).toBe('default');
|
|
37
|
+
storage.set('cell:theme', JSON.stringify({ id: 'dark', label: 'Stale' }));
|
|
38
|
+
expect((await current()).theme?.id).toBe('default');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('saves only the id; the configuration wins over what was saved before', async () => {
|
|
42
|
+
const { manager } = await current();
|
|
43
|
+
const [, dark] = await manager.get();
|
|
44
|
+
manager.currentSubject.next({ ...dark, label: 'Changed' });
|
|
45
|
+
expect(storage.get('cell:theme')).toBe(dark.id);
|
|
46
|
+
expect((await current()).theme?.label).toBe(themes[dark.id as keyof typeof themes].label);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -7,7 +7,7 @@ export class ThemeManagerImpl<T> implements ThemeManager<T> {
|
|
|
7
7
|
|
|
8
8
|
protected readonly themeStorageKey = 'cell:theme';
|
|
9
9
|
|
|
10
|
-
@Value('
|
|
10
|
+
@Value('widget.themes')
|
|
11
11
|
protected readonly themesForConfig: { [id: string]: Theme<T> };
|
|
12
12
|
|
|
13
13
|
@Autowired(Theme) @Optional()
|
|
@@ -17,23 +17,27 @@ export class ThemeManagerImpl<T> implements ThemeManager<T> {
|
|
|
17
17
|
|
|
18
18
|
currentSubject = new BehaviorSubject<Theme<T> | undefined>(undefined);
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Selects the theme saved by its id, else `default`, else the first one. Only the id is saved, so a
|
|
22
|
+
* theme changed in the configuration takes effect on the next load.
|
|
23
|
+
*/
|
|
20
24
|
@PostConstruct()
|
|
21
25
|
init() {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (this.themesForConfig) {
|
|
27
|
-
this.currentSubject.next(this.themesForConfig[DEFAULT_THEME]);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
this.currentSubject.subscribe(theme => {
|
|
26
|
+
(async () => {
|
|
27
|
+
const themes = await this.get();
|
|
28
|
+
const id = localStorage.getItem(this.themeStorageKey);
|
|
29
|
+
const theme = themes.find(t => t.id === id) ?? themes.find(t => t.id === DEFAULT_THEME) ?? themes[0];
|
|
31
30
|
if (theme) {
|
|
32
|
-
|
|
33
|
-
} else {
|
|
34
|
-
localStorage.removeItem(this.themeStorageKey);
|
|
31
|
+
this.currentSubject.next(theme);
|
|
35
32
|
}
|
|
36
|
-
|
|
33
|
+
this.currentSubject.subscribe(t => {
|
|
34
|
+
if (t) {
|
|
35
|
+
localStorage.setItem(this.themeStorageKey, t.id);
|
|
36
|
+
} else {
|
|
37
|
+
localStorage.removeItem(this.themeStorageKey);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
})();
|
|
37
41
|
}
|
|
38
42
|
|
|
39
43
|
async get(): Promise<Theme<T>[]> {
|
|
@@ -9,6 +9,8 @@ export abstract class AbstractWidgetFactory<T> implements WidgetFactory<T> {
|
|
|
9
9
|
|
|
10
10
|
priority = 500;
|
|
11
11
|
|
|
12
|
+
abstract readonly type: string;
|
|
13
|
+
|
|
12
14
|
async create(widgetModel: WidgetModel): Promise<Widget<T>> {
|
|
13
15
|
const { children = [] } = widgetModel;
|
|
14
16
|
|
|
@@ -18,16 +20,16 @@ export abstract class AbstractWidgetFactory<T> implements WidgetFactory<T> {
|
|
|
18
20
|
area: widgetModel.area,
|
|
19
21
|
priority: widgetModel.priority,
|
|
20
22
|
render: async () => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
return this.doRender(widgetModel, await Promise.all(children.map(c => WidgetUtil.create<T>(c))));
|
|
23
|
+
// Evaluated on a copy: the model keeps its `${...}` expressions for the next render.
|
|
24
|
+
const props = widgetModel.props && this.expressionHandler.handle(WidgetUtil.copyProps(widgetModel.props));
|
|
25
|
+
return this.doRender({ ...widgetModel, props }, await Promise.all(children.map(c => WidgetUtil.create<T>(c))));
|
|
25
26
|
}
|
|
26
27
|
};
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
async support(widgetModel: WidgetModel): Promise<boolean> {
|
|
30
|
-
|
|
31
|
+
// Not the class name: production builds minify it.
|
|
32
|
+
return widgetModel.type === this.type;
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
protected abstract doRender(widgetModel: WidgetModel, children: Widget<T>[]): Promise<T>;
|
|
@@ -10,7 +10,7 @@ export class WidgetManagerImpl<T> implements WidgetManager<T> {
|
|
|
10
10
|
constructor(
|
|
11
11
|
@Autowired(Widget) @Optional() protected readonly widgets: Widget<T>[],
|
|
12
12
|
@Autowired(WidgetModel) @Optional() protected readonly widgetModels: WidgetModel[],
|
|
13
|
-
@Value('
|
|
13
|
+
@Value('widget.widgets') protected readonly widgetModelsForConfig: { [id: string]: WidgetModel }
|
|
14
14
|
) {}
|
|
15
15
|
|
|
16
16
|
async render(area: string): Promise<T[]> {
|
|
@@ -24,8 +24,8 @@ export class WidgetManagerImpl<T> implements WidgetManager<T> {
|
|
|
24
24
|
const config = { ...this.widgetModelsForConfig };
|
|
25
25
|
this.widgets.forEach(w => {
|
|
26
26
|
const c = config[w.id];
|
|
27
|
-
if (
|
|
28
|
-
w.area = c.area;
|
|
27
|
+
if (c) {
|
|
28
|
+
w.area = c.area ?? w.area;
|
|
29
29
|
w.priority = c.priority === undefined ? w.priority : c.priority;
|
|
30
30
|
w.visible = c.visible === undefined ? w.visible : c.visible;
|
|
31
31
|
delete config[w.id];
|
|
@@ -28,6 +28,8 @@ export interface WidgetModel {
|
|
|
28
28
|
|
|
29
29
|
export interface WidgetFactory<T> {
|
|
30
30
|
priority: number;
|
|
31
|
+
/** The {@link WidgetModel.type} this factory renders. */
|
|
32
|
+
readonly type: string;
|
|
31
33
|
create(widgetModel: WidgetModel): Promise<Widget<T>>;
|
|
32
34
|
support(widgetModel: WidgetModel): Promise<boolean>;
|
|
33
35
|
}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { ContainerUtil, Prioritizeable } from '@celljs/core';
|
|
2
2
|
import { WidgetModel, WidgetFactory, Widget } from './widget-protocol';
|
|
3
3
|
|
|
4
|
-
let widgetFactories: WidgetFactory<any>[];
|
|
5
|
-
|
|
6
4
|
export namespace WidgetUtil {
|
|
7
5
|
export async function create<T>(widgetModel: WidgetModel): Promise<Widget<T>> {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
6
|
+
// Looked up every time, not cached: a new container (tests, HMR) brings new factories.
|
|
7
|
+
const widgetFactories = Prioritizeable.prioritizeAllSync(ContainerUtil.getAll<WidgetFactory<T>>(WidgetFactory)).map(p => p.value);
|
|
12
8
|
for (const factory of widgetFactories) {
|
|
13
9
|
if (await factory.support(widgetModel)) {
|
|
14
10
|
const widget = await factory.create(widgetModel);
|
|
@@ -18,6 +14,27 @@ export namespace WidgetUtil {
|
|
|
18
14
|
throw new Error(`WidgetModel {id: ${widgetModel.id}, type: ${widgetModel.type}} there is no matching widget factory.`);
|
|
19
15
|
}
|
|
20
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Copies the plain objects and arrays of widget props; anything else (components, functions,
|
|
19
|
+
* class instances) is kept as is.
|
|
20
|
+
*/
|
|
21
|
+
export function copyProps<P>(props: P): P {
|
|
22
|
+
if (Array.isArray(props)) {
|
|
23
|
+
return props.map(copyProps) as P;
|
|
24
|
+
}
|
|
25
|
+
if (props && typeof props === 'object') {
|
|
26
|
+
const proto = Object.getPrototypeOf(props);
|
|
27
|
+
if (proto === Object.prototype || proto === null) {
|
|
28
|
+
const copy: Record<string, unknown> = {};
|
|
29
|
+
for (const [key, value] of Object.entries(props)) {
|
|
30
|
+
copy[key] = copyProps(value);
|
|
31
|
+
}
|
|
32
|
+
return copy as P;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return props;
|
|
36
|
+
}
|
|
37
|
+
|
|
21
38
|
export async function render<T>(widgetModel: WidgetModel): Promise<T> {
|
|
22
39
|
const widget = await WidgetUtil.create<T>(widgetModel);
|
|
23
40
|
return widget.render();
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
import { autoBind, Component, Constant, ContainerUtil } from '@celljs/core';
|
|
3
|
+
import { ApplicationFactory } from '@celljs/core/lib/common/application/application-factory';
|
|
4
|
+
import { Widget as WidgetDecorator } from '../annotation';
|
|
5
|
+
import { AbstractWidgetFactory } from './widget-factory';
|
|
6
|
+
import { Widget, WidgetFactory, WidgetManager, WidgetModel, WidgetType } from './widget-protocol';
|
|
7
|
+
import { WidgetUtil } from './widget-util';
|
|
8
|
+
import './widget-manager';
|
|
9
|
+
|
|
10
|
+
/** Production builds minify class names, so a factory must not be matched by its name. */
|
|
11
|
+
@Component(WidgetFactory)
|
|
12
|
+
export class Qn extends AbstractWidgetFactory<string> {
|
|
13
|
+
readonly type = 'Text';
|
|
14
|
+
|
|
15
|
+
protected async doRender(model: WidgetModel): Promise<string> {
|
|
16
|
+
return `${model.id}:${model.props?.text ?? ''}`;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** What @celljs/react does for @Widget: render the component of the model. */
|
|
21
|
+
@Component(WidgetFactory)
|
|
22
|
+
export class ComponentFactory extends AbstractWidgetFactory<string> {
|
|
23
|
+
readonly type: string = WidgetType.Decorator;
|
|
24
|
+
|
|
25
|
+
protected async doRender(model: WidgetModel): Promise<string> {
|
|
26
|
+
return model.matedata!.component();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@WidgetDecorator({ id: 'copyright', area: 'footer', priority: 10, component: () => '(c)' })
|
|
31
|
+
export class CopyrightWidget {}
|
|
32
|
+
|
|
33
|
+
@WidgetDecorator({ area: 'aside', component: () => 'logo' })
|
|
34
|
+
export class LogoWidget {}
|
|
35
|
+
|
|
36
|
+
@Constant(Widget, { id: 'banner', area: 'header', priority: 900, visible: true, render: async () => 'banner' })
|
|
37
|
+
export class BannerWidget {}
|
|
38
|
+
|
|
39
|
+
// autoBind() takes what was registered since the previous call: one module for every test.
|
|
40
|
+
const widgetModule = autoBind();
|
|
41
|
+
const boot = (widgets: Record<string, Partial<WidgetModel>> = {}) =>
|
|
42
|
+
ApplicationFactory.create({ app: { name: 'Cell' }, widget: { widgets } }, widgetModule);
|
|
43
|
+
const manager = () => ContainerUtil.get<WidgetManager<string>>(WidgetManager);
|
|
44
|
+
|
|
45
|
+
describe('@celljs/widget', () => {
|
|
46
|
+
|
|
47
|
+
it('matches a factory by its type, not by its class name', async () => {
|
|
48
|
+
await boot({ hello: { type: 'Text', area: 'header', props: { text: 'hi' } } });
|
|
49
|
+
expect(await manager().render('header')).toEqual(['banner', 'hello:hi']);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('a widget without configuration keeps its area; configuration without an area only changes the rest', async () => {
|
|
53
|
+
await boot({ banner: { priority: 1 } });
|
|
54
|
+
expect(await manager().render('header')).toEqual(['banner']);
|
|
55
|
+
const [banner] = await manager().get('header');
|
|
56
|
+
expect(banner.priority).toBe(1);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('configuration hides a widget and moves another to an area', async () => {
|
|
60
|
+
await boot({ banner: { visible: false }, hello: { type: 'Text', area: 'footer', priority: 1 } });
|
|
61
|
+
expect(await manager().render('header')).toEqual([]);
|
|
62
|
+
expect((await manager().get('footer')).map(w => w.id)).toEqual(['copyright', 'hello']);
|
|
63
|
+
expect(await manager().render('footer')).toEqual(['(c)', 'hello:']);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('the id of a @Widget defaults to the name of the decorated class', async () => {
|
|
67
|
+
await boot();
|
|
68
|
+
expect((await manager().get('aside')).map(w => w.id)).toEqual(['LogoWidget']);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('evaluates ${...} in props on a copy, on every render', async () => {
|
|
72
|
+
await boot();
|
|
73
|
+
const model: WidgetModel = { id: 'w', type: 'Text', priority: 1, visible: true, props: { text: 'by ${app.name}', nested: ['${app.name}'] } };
|
|
74
|
+
const widget = await WidgetUtil.create<string>(model);
|
|
75
|
+
expect(await widget.render()).toBe('w:by Cell');
|
|
76
|
+
expect(await widget.render()).toBe('w:by Cell');
|
|
77
|
+
expect(model.props).toEqual({ text: 'by ${app.name}', nested: ['${app.name}'] });
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('fails with the widget id when no factory supports its type', async () => {
|
|
81
|
+
await boot();
|
|
82
|
+
await expect(WidgetUtil.create({ id: 'x', type: 'Unknown', priority: 1, visible: true })).rejects.toThrow('id: x');
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('copyProps copies plain objects and arrays, keeps the rest', () => {
|
|
86
|
+
class Model {}
|
|
87
|
+
const fn = () => undefined;
|
|
88
|
+
const instance = new Model();
|
|
89
|
+
const props = { a: { b: [1, { c: 2 }] }, fn, instance };
|
|
90
|
+
const copy = WidgetUtil.copyProps(props);
|
|
91
|
+
expect(copy).toEqual(props);
|
|
92
|
+
expect(copy.a).not.toBe(props.a);
|
|
93
|
+
expect(copy.a.b[1]).not.toBe(props.a.b[1]);
|
|
94
|
+
expect(copy.fn).toBe(fn);
|
|
95
|
+
expect(copy.instance).toBe(instance);
|
|
96
|
+
});
|
|
97
|
+
});
|