@omnia/velcron 7.0.513-dev → 7.0.515-dev

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.
@@ -2,7 +2,7 @@ import { VelcronComponentDescriptor } from "./VelcronDescriptors";
2
2
  import { VelcronEvent, VelcronOnChangedEvent, VelcronOnClosedEvent, VelcronOnCloseRequestedEvent, VelcronOnLoadEvent, VelcronOnPressEvent } from "./VelcronEvents";
3
3
  import { VelcroncomponentArrayType, VelcronPrimitiveType } from "./VelcronTypes";
4
4
  import { AssignOperators, VelcronHorizontalAlignments, VelcronIconTypes, VelcronActionTypes, VerticalAlignments } from "./Enums";
5
- import { useVelcronThemingStore } from "..";
5
+ import { ColorSchema, useVelcronThemingStore } from "..";
6
6
  export interface ResolvedComponentRenderer {
7
7
  component: unknown;
8
8
  definition: VelcronDefinition;
@@ -33,6 +33,8 @@ export interface VelcronRenderContext {
33
33
  rootContext: DynamicViewModel;
34
34
  currentContext: DynamicViewModel;
35
35
  theming?: ReturnType<typeof useVelcronThemingStore>;
36
+ colorSchemaName?: string;
37
+ colorSchema?: ColorSchema;
36
38
  actions?: {
37
39
  [name: string]: [];
38
40
  };
@@ -91,6 +93,9 @@ export interface VelcronDefinitionBase {
91
93
  */
92
94
  key?: string;
93
95
  }
96
+ export interface VelcronCustomThemeSettings {
97
+ colorSchema?: string;
98
+ }
94
99
  export interface VelcronDefinition extends VelcronDefinitionBase {
95
100
  body?: Array<VelcronDefinition>;
96
101
  style?: VelcronStyling;
@@ -202,7 +207,7 @@ export interface VelcronIconDefinition extends VelcronDefinition {
202
207
  size?: number;
203
208
  events?: VelcronOnPressEvent;
204
209
  }
205
- export interface VelcronFlexViewDefinition extends VelcronDefinition {
210
+ export interface VelcronFlexViewDefinition extends VelcronDefinition, VelcronCustomThemeSettings {
206
211
  type: "FlexView";
207
212
  column?: boolean;
208
213
  body: Array<VelcronDefinition>;
@@ -212,7 +217,6 @@ export interface VelcronFlexViewDefinition extends VelcronDefinition {
212
217
  grow?: number;
213
218
  border?: VelcronBorder;
214
219
  borderRadius?: VelcronDimensions;
215
- colorSchema?: string;
216
220
  width: string;
217
221
  }
218
222
  export interface VelcronDimensions {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@omnia/velcron",
3
3
  "license": "MIT",
4
- "version": "7.0.513-dev",
4
+ "version": "7.0.515-dev",
5
5
  "description": "Provide Omnia Velcron Stuffs.",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -1,4 +1,4 @@
1
- import { BuiltInComponentRenderers, DynamicViewModel, ResolvedComponentRenderer, VelcronDefinition, VelcronRenderContext } from "../models";
1
+ import { BuiltInComponentRenderers, DynamicViewModel, ResolvedComponentRenderer, VelcronCustomComponentDefinition, VelcronDefinition, VelcronRenderContext } from "../models";
2
2
  export declare class VelcronRenderers {
3
3
  private static components;
4
4
  static registerComponent(type: string, component: any): void;
@@ -6,5 +6,31 @@ export declare class VelcronRenderers {
6
6
  static hasComponent(type: string): any;
7
7
  static registerComponents(components: BuiltInComponentRenderers): void;
8
8
  static getComponent(definition: VelcronDefinition, renderContext: VelcronRenderContext): ResolvedComponentRenderer;
9
+ static definitionContainsCustomColorSchema(definition: VelcronDefinition): boolean;
10
+ static createNewRendererContext(currentRenderCtx: VelcronRenderContext, definition: VelcronDefinition, newViewModel?: DynamicViewModel): {
11
+ rootContext: object;
12
+ theming: {
13
+ state: {
14
+ currentTheme: import("@omnia/fx-models").ThemeDefinitionV2;
15
+ };
16
+ get: {
17
+ colorSchema: (schema: string) => import("@omnia/fx-models").ColorSchema;
18
+ typography: (name: string) => import("@omnia/fx-models").TypographyType;
19
+ color: (schemaName: string, colorType: string) => string;
20
+ };
21
+ actions: {
22
+ setTheme(newTheme: import("@omnia/fx-models").ThemeDefinitionV2): void;
23
+ };
24
+ };
25
+ currentContext: object;
26
+ actions: {
27
+ [name: string]: [];
28
+ };
29
+ components: VelcronCustomComponentDefinition[];
30
+ hooks: import("../models").VelcronRenderContextHooks;
31
+ computed: {
32
+ [name: string]: [];
33
+ };
34
+ };
9
35
  static ensureRenderContext(rendererInfo: ResolvedComponentRenderer, definition: VelcronDefinition, currentRenderCtx: VelcronRenderContext, newViewModel?: DynamicViewModel): VelcronRenderContext;
10
36
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VelcronRenderers = void 0;
4
4
  const VelcronLogger_1 = require("./VelcronLogger");
5
5
  const VelcronData_1 = require("./VelcronData");
6
+ const stores_1 = require("../stores");
6
7
  class VelcronRenderers {
7
8
  static registerComponent(type, component) {
8
9
  type = type.toLowerCase();
@@ -59,19 +60,37 @@ class VelcronRenderers {
59
60
  }
60
61
  return result;
61
62
  }
63
+ static definitionContainsCustomColorSchema(definition) {
64
+ return (definition.colorSchema && definition.colorSchema !== "");
65
+ }
66
+ static createNewRendererContext(currentRenderCtx, definition, newViewModel) {
67
+ const result = {
68
+ rootContext: currentRenderCtx.rootContext,
69
+ theming: currentRenderCtx.theming,
70
+ currentContext: newViewModel ? newViewModel : currentRenderCtx.currentContext,
71
+ actions: currentRenderCtx.actions,
72
+ components: currentRenderCtx.components,
73
+ hooks: currentRenderCtx.hooks,
74
+ computed: currentRenderCtx.computed,
75
+ };
76
+ if (VelcronRenderers.definitionContainsCustomColorSchema(definition)) {
77
+ const schema = VelcronData_1.VelcronData.dataBind(result, definition.colorSchema);
78
+ result.colorSchemaName = stores_1.ReactivitySystem.makeReactive(schema);
79
+ result.colorSchema = result.theming.get.colorSchema(result.colorSchemaName);
80
+ }
81
+ else {
82
+ result.colorSchemaName = currentRenderCtx.colorSchemaName;
83
+ result.colorSchema = currentRenderCtx.colorSchema;
84
+ }
85
+ return result;
86
+ }
62
87
  static ensureRenderContext(rendererInfo, definition, currentRenderCtx, newViewModel) {
63
88
  //Ensure we have the correct render context passing properties etc to sub components
64
89
  let result = currentRenderCtx;
65
- if (rendererInfo.customComponent || newViewModel) {
66
- result = {
67
- rootContext: currentRenderCtx.rootContext,
68
- theming: currentRenderCtx.theming,
69
- currentContext: newViewModel ? newViewModel : currentRenderCtx.currentContext,
70
- actions: currentRenderCtx.actions,
71
- components: currentRenderCtx.components,
72
- hooks: currentRenderCtx.hooks,
73
- computed: currentRenderCtx.computed
74
- };
90
+ if (rendererInfo.customComponent
91
+ || newViewModel ||
92
+ VelcronRenderers.definitionContainsCustomColorSchema(definition)) {
93
+ result = VelcronRenderers.createNewRendererContext(currentRenderCtx, definition, newViewModel);
75
94
  if (rendererInfo.customComponent) {
76
95
  //Fetch the custom component definition
77
96
  const customDef = rendererInfo.definition;
@@ -22,10 +22,10 @@ class VelcronStyles {
22
22
  else if (definition.type === VelcronConstants_1.VelcronConstants.components.text) {
23
23
  const textDefinition = definition;
24
24
  if (textDefinition.color) {
25
- styleBase["color"] = renderCtx.theming.get.colorFromActiveSchema(textDefinition.color);
25
+ styleBase["color"] = renderCtx.theming.get.color(renderCtx.colorSchemaName, textDefinition.color);
26
26
  }
27
27
  else {
28
- styleBase["color"] = renderCtx.theming.get.activeColorSchema().onBase.color;
28
+ styleBase["color"] = renderCtx.colorSchema.onBase.color;
29
29
  }
30
30
  }
31
31
  else if (definition.type === VelcronConstants_1.VelcronConstants.components.flexView) {
@@ -53,8 +53,8 @@ class VelcronStyles {
53
53
  }
54
54
  }
55
55
  if (flexViewDefinition.colorSchema && flexViewDefinition.colorSchema != "") {
56
- const color = renderCtx.theming.get.activeColorSchema().base.color;
57
- styleBase["backgroundColor"] = renderCtx.theming.get.activeColorSchema().base.color;
56
+ //styleBase["backgroundColor"] = renderCtx.theming.get.activeColorSchema().base.color;
57
+ styleBase["backgroundColor"] = renderCtx.colorSchema.base.color;
58
58
  }
59
59
  }
60
60
  return VelcronStyles.styleProvider(styleBase, definition, renderCtx);
@@ -1,9 +1,12 @@
1
- export declare const defineVelcronStore: <TState, TGetters, TActions>(name: string, definition: {
2
- state: TState;
3
- getters: (state: TState) => TGetters;
4
- actions: (state: TState) => TActions;
5
- }) => () => {
6
- state: TState;
1
+ export declare const defineVelcronStore: <TSetup extends {
2
+ state: object;
3
+ privateState?: object;
4
+ }, TGetters, TActions>(name: string, definition: {
5
+ setup: () => TSetup;
6
+ getters?: (state: TSetup["state"], privateState?: TSetup["privateState"]) => TGetters;
7
+ actions?: (state: TSetup["state"], privateState?: TSetup["privateState"]) => TActions;
8
+ }) => (newStateWithName?: string) => {
9
+ state: TSetup["state"];
7
10
  get: TGetters;
8
11
  actions: TActions;
9
12
  };
@@ -4,17 +4,29 @@ exports.defineVelcronStore = void 0;
4
4
  const ReactivitySystem_1 = require("./ReactivitySystem");
5
5
  const stateMap = new Map();
6
6
  const defineVelcronStore = (name, definition) => {
7
- const result = () => {
7
+ const result = (newStateWithName) => {
8
+ if (newStateWithName && newStateWithName !== "" && newStateWithName !== name) {
9
+ name = newStateWithName;
10
+ }
8
11
  if (!stateMap.has(name)) {
9
- stateMap.set(name, ReactivitySystem_1.ReactivitySystem.makeReactive(definition.state));
12
+ stateMap.set(name, ReactivitySystem_1.ReactivitySystem.makeReactive(definition.setup()));
10
13
  }
11
14
  const reactiveState = stateMap.get(name);
12
15
  return {
13
- state: reactiveState,
14
- get: definition.getters(reactiveState),
15
- actions: definition.actions(reactiveState)
16
+ state: reactiveState.state,
17
+ get: definition.getters(reactiveState.state, reactiveState.privateState),
18
+ actions: definition.actions(reactiveState.state, reactiveState.privateState)
16
19
  };
17
20
  };
18
21
  return result;
19
22
  };
20
23
  exports.defineVelcronStore = defineVelcronStore;
24
+ const pelle = (0, exports.defineVelcronStore)("pelle", {
25
+ setup() {
26
+ return {
27
+ state: {
28
+ test: "Hello"
29
+ },
30
+ };
31
+ }
32
+ });
@@ -1,16 +1,14 @@
1
- import { ColorSchema, ThemeDefinitionV2, TypographyType } from "..";
2
- export declare const useVelcronThemingStore: () => {
1
+ import { ThemeDefinitionV2, TypographyType } from "..";
2
+ export declare const useVelcronThemingStore: (newStateWithName?: string) => {
3
3
  state: {
4
4
  currentTheme: ThemeDefinitionV2;
5
- activeSchema: string;
6
5
  };
7
6
  get: {
8
- activeColorSchema: () => ColorSchema;
7
+ colorSchema: (schema: string) => import("..").ColorSchema;
9
8
  typography: (name: string) => TypographyType;
10
- colorFromActiveSchema: (name: string) => string;
9
+ color: (schemaName: string, colorType: string) => string;
11
10
  };
12
11
  actions: {
13
- setActiveSchema(name: string): void;
14
12
  setTheme(newTheme: ThemeDefinitionV2): void;
15
13
  };
16
14
  };
@@ -4,34 +4,37 @@ exports.useVelcronThemingStore = void 0;
4
4
  const __1 = require("..");
5
5
  const VelcronStore_1 = require("./VelcronStore");
6
6
  exports.useVelcronThemingStore = (0, VelcronStore_1.defineVelcronStore)("VelcronTheming", {
7
- state: {
8
- currentTheme: {},
9
- activeSchema: ""
7
+ setup() {
8
+ return {
9
+ state: {
10
+ currentTheme: {}
11
+ }
12
+ };
10
13
  },
11
14
  getters(state) {
12
- const activeColorSchema = () => {
13
- if (state.activeSchema === __1.ColorSchemaTypes.primary) {
15
+ const colorSchema = (schema) => {
16
+ if (schema === __1.ColorSchemaTypes.primary) {
14
17
  return state.currentTheme?.primary;
15
18
  }
16
- else if (state.activeSchema === __1.ColorSchemaTypes.secondary) {
19
+ else if (schema === __1.ColorSchemaTypes.secondary) {
17
20
  return state.currentTheme?.secondary;
18
21
  }
19
- else if (state.activeSchema === __1.ColorSchemaTypes.accent1) {
22
+ else if (schema === __1.ColorSchemaTypes.accent1) {
20
23
  return state.currentTheme?.accent1;
21
24
  }
22
- else if (state.activeSchema === __1.ColorSchemaTypes.accent2) {
25
+ else if (schema === __1.ColorSchemaTypes.accent2) {
23
26
  return state.currentTheme?.accent2;
24
27
  }
25
- else if (state.activeSchema === __1.ColorSchemaTypes.accent3) {
28
+ else if (schema === __1.ColorSchemaTypes.accent3) {
26
29
  return state.currentTheme?.accent3;
27
30
  }
28
- else if (state.activeSchema === __1.ColorSchemaTypes.background) {
31
+ else if (schema === __1.ColorSchemaTypes.background) {
29
32
  return state.currentTheme?.background;
30
33
  }
31
- else if (state.activeSchema === __1.ColorSchemaTypes.neutral) {
34
+ else if (schema === __1.ColorSchemaTypes.neutral) {
32
35
  return state.currentTheme?.neutral;
33
36
  }
34
- else if (state.activeSchema === __1.ColorSchemaTypes.error) {
37
+ else if (schema === __1.ColorSchemaTypes.error) {
35
38
  return state.currentTheme?.error;
36
39
  }
37
40
  return state.currentTheme?.background;
@@ -57,44 +60,42 @@ exports.useVelcronThemingStore = (0, VelcronStore_1.defineVelcronStore)("Velcron
57
60
  }
58
61
  return state.currentTheme.typography.text;
59
62
  };
60
- const colorFromActiveSchema = (name) => {
61
- if (name === __1.ColorTypes.base) {
62
- return activeColorSchema().base.color;
63
+ const color = (schemaName, colorType) => {
64
+ const mappedColorSchema = colorSchema(schemaName);
65
+ if (colorType === __1.ColorTypes.base) {
66
+ return mappedColorSchema.base.color;
63
67
  }
64
- else if (name === __1.ColorTypes.baseTone) {
65
- return activeColorSchema().base.colorToned;
68
+ else if (colorType === __1.ColorTypes.baseTone) {
69
+ return mappedColorSchema.base.colorToned;
66
70
  }
67
- else if (name === __1.ColorTypes.onBase) {
68
- return activeColorSchema().onBase.color;
71
+ else if (colorType === __1.ColorTypes.onBase) {
72
+ return mappedColorSchema.onBase.color;
69
73
  }
70
- else if (name === __1.ColorTypes.onBaseTone) {
71
- return activeColorSchema().onBase.colorToned;
74
+ else if (colorType === __1.ColorTypes.onBaseTone) {
75
+ return mappedColorSchema.onBase.colorToned;
72
76
  }
73
- else if (name === __1.ColorTypes.container) {
74
- return activeColorSchema().container.color;
77
+ else if (colorType === __1.ColorTypes.container) {
78
+ return mappedColorSchema.container.color;
75
79
  }
76
- else if (name === __1.ColorTypes.containerTone) {
77
- return activeColorSchema().container.colorToned;
80
+ else if (colorType === __1.ColorTypes.containerTone) {
81
+ return mappedColorSchema.container.colorToned;
78
82
  }
79
- else if (name === __1.ColorTypes.onContainer) {
80
- return activeColorSchema().onContainer.color;
83
+ else if (colorType === __1.ColorTypes.onContainer) {
84
+ return mappedColorSchema.onContainer.color;
81
85
  }
82
- else if (name === __1.ColorTypes.onContainerTone) {
83
- return activeColorSchema().onContainer.colorToned;
86
+ else if (colorType === __1.ColorTypes.onContainerTone) {
87
+ return mappedColorSchema.onContainer.colorToned;
84
88
  }
85
- return name;
89
+ return colorType;
86
90
  };
87
91
  return {
88
- activeColorSchema,
92
+ colorSchema,
89
93
  typography,
90
- colorFromActiveSchema
94
+ color
91
95
  };
92
96
  },
93
97
  actions(state) {
94
98
  return {
95
- setActiveSchema(name) {
96
- state.activeSchema = name;
97
- },
98
99
  setTheme(newTheme) {
99
100
  state.currentTheme = newTheme;
100
101
  }