@bdlite/domains 1.1.28 → 1.1.30

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.
@@ -0,0 +1,6 @@
1
+ import { createSubChannelKit } from '@bdlite/observable/es/create-observable-kit'
2
+ import { CHANNEL_NAME } from '../constants'
3
+
4
+ const { subscribe } = createSubChannelKit({ channelName: CHANNEL_NAME }, { relay: 1 })
5
+
6
+ export const subscribeLayout = subscribe
@@ -0,0 +1,6 @@
1
+ import { createSubChannelKit } from '@bdlite/observable/es/create-observable-kit'
2
+ import { MENU_ITEM_CHANNEL_NAME } from '../constants'
3
+
4
+ const { subscribe } = createSubChannelKit({ channelName: MENU_ITEM_CHANNEL_NAME }, { relay: 1 })
5
+
6
+ export const subscribeMenuItem = subscribe
@@ -0,0 +1,6 @@
1
+ import { createSubChannelKit } from '@bdlite/observable/es/create-observable-kit'
2
+ import { MENU_CHANNEL_NAME } from '../constants'
3
+
4
+ const { subscribe } = createSubChannelKit({ channelName: MENU_CHANNEL_NAME }, { relay: 1 })
5
+
6
+ export const subscribeMenu = subscribe
@@ -9,4 +9,15 @@ export const LAYOUT_MODE = {
9
9
  BOTH: 'both',
10
10
  }
11
11
  export const DEFAULT_LAYOUT_MODE = LAYOUT_MODE.HEADER
12
- export const DEFAULT_LAYOUT_DATA = { systemName: '', showFooter: false, layoutMode: DEFAULT_LAYOUT_MODE }
12
+
13
+ export const LAYOUT_THEME = {
14
+ DARK: 'dark',
15
+ LIGHT: 'light',
16
+ }
17
+ export const DEFAULT_LAYOUT_THEME = LAYOUT_THEME.DARK
18
+
19
+ export const DEFAULT_LAYOUT_DATA = {
20
+ systemName: '', showFooter: false,
21
+ theme: DEFAULT_LAYOUT_THEME,
22
+ layoutMode: DEFAULT_LAYOUT_MODE,
23
+ }
@@ -0,0 +1,115 @@
1
+ import { isObject } from '@bdlite/strategy'
2
+ import storage from '@bdlite/helpers/es/storage'
3
+ import { createObservableKit } from '@bdlite/observable/es/create-observable-kit'
4
+
5
+
6
+ export const DEFAULT_TEAM_STATUS = { hide: true }
7
+ export const DEFALUT_CURRENT_TEAM = { id: null, teamId: null, teamName: '' }
8
+
9
+
10
+ const KEY = 'team_data'
11
+
12
+ const { getData: getStateData, subscribe: subscribeState, publish: publishState } = createObservableKit(DEFAULT_TEAM_STATUS)
13
+
14
+ const { getData, subscribe, publish } = createObservableKit({ ...DEFALUT_CURRENT_TEAM })
15
+ const { subscribe: subscribeCache, publish: publishCache } = createObservableKit({ ...DEFALUT_CURRENT_TEAM })
16
+
17
+ let _isCleared = false
18
+ let _currentTeam = getData()
19
+
20
+
21
+
22
+ /**
23
+ * @function subscribeTeam
24
+ * @param {function | object} mountedFunOrConfig callback | { cache = false, ...config }
25
+ * @param {?function} unmountedFun
26
+ * @returns {function} unsubscribe
27
+ */
28
+ export function subscribeTeam(mountedFunOrConfig, unmountedFun) {
29
+ if (isObject(mountedFunOrConfig)) {
30
+ const { cache = false, ...config } = mountedFunOrConfig
31
+ return cache ? subscribeCache(config, unmountedFun) : subscribe(config, unmountedFun)
32
+ }
33
+ return subscribe(mountedFunOrConfig, unmountedFun)
34
+
35
+ }
36
+
37
+ /**
38
+ * @function publishTeam
39
+ * @param {?object} { cache = false, all = false }
40
+ */
41
+ export function publishTeam({ cache = false, all = false } = {}) {
42
+ const team = getTeam()
43
+
44
+ if (all) {
45
+ publishCache(team)
46
+ publish(team)
47
+ return
48
+ }
49
+
50
+ if (cache) {
51
+ publishCache(team)
52
+ } else {
53
+ publish(team)
54
+ }
55
+ }
56
+
57
+ /**
58
+ * @function subscribeTeamStatus
59
+ * @param {function | object} mountedFunOrConfig
60
+ * @param {?function} unmountedFun
61
+ * @returns {function} unsubscribe
62
+ */
63
+ export const subscribeTeamStatus = subscribeState
64
+
65
+ /**
66
+ * @function publishTeamStatus
67
+ * @param {?object} nextState
68
+ */
69
+ export function publishTeamStatus(nextState = {}) {
70
+ publishState({ ...getStateData(), ...nextState })
71
+ }
72
+
73
+ /**
74
+ * @function showTeamSelector
75
+ * @param {?boolean} show
76
+ */
77
+ export function showTeamSelector(show = true) {
78
+ publishTeamStatus({ hide: !show })
79
+ }
80
+
81
+
82
+
83
+ export function storeTeam(teamId = '', teamName = '', leaderName = '') {
84
+ const name = `${teamName}`
85
+ Object.assign(_currentTeam, { id: teamId, teamId, leaderName }, name ? { teamName: name } : {})
86
+ storage.appendObject(KEY, _currentTeam)
87
+ _isCleared = false
88
+ }
89
+
90
+ export function clearTeam({ stayStored = false } = {}) {
91
+ _currentTeam = { ...DEFALUT_CURRENT_TEAM }
92
+ _isCleared = true
93
+
94
+ if (!stayStored) {
95
+ storage.remove(KEY)
96
+ }
97
+ }
98
+
99
+ export function getTeam() {
100
+ if (_currentTeam.teamId === null && !_isCleared) {
101
+ Object.assign(_currentTeam, storage.getObject(KEY))
102
+ }
103
+
104
+ const { teamId, teamName = '', ...rest } = _currentTeam
105
+
106
+ if(teamId == 'null'){
107
+ return { teamId: '', teamName, ...rest }
108
+ }
109
+
110
+ return { teamId, teamName, ...rest }
111
+ }
112
+
113
+ export function getTeamId() {
114
+ return getTeam().teamId
115
+ }
@@ -0,0 +1,91 @@
1
+ import { isObject } from '@bdlite/strategy'
2
+ import storage from '@bdlite/helpers/es/storage'
3
+ import { createObservableKit } from '@bdlite/observable/es/create-observable-kit'
4
+
5
+ export const DEFALUT_CURRENT_PROJECT = { id: null, projectId: null, key: '', projectName: '' }
6
+
7
+ const KEY = 'project_data'
8
+
9
+ const { subscribe: cacheSubscribe, publish: cachePublish } = createObservableKit({ ...DEFALUT_CURRENT_PROJECT })
10
+ const { getData: getProjectData, subscribe, publish: projectPublish } = createObservableKit({ ...DEFALUT_CURRENT_PROJECT })
11
+
12
+ let _isCleared = false
13
+ let _currentProject = getProjectData()
14
+
15
+
16
+ /**
17
+ * @function subscribeProject
18
+ * @param {function | object} mountedFunOrConfig callback | { cache = false, ...config }
19
+ * @param {?function} unmountedFun
20
+ * @returns {function} unsubscribe
21
+ */
22
+ export function subscribeProject(mountedFunOrConfig, unmountedFun) {
23
+ if (isObject(mountedFunOrConfig)) {
24
+ const { cache = false, ...config } = mountedFunOrConfig
25
+ return cache ? cacheSubscribe(config, unmountedFun) : subscribe(config, unmountedFun)
26
+ }
27
+
28
+ return subscribe(mountedFunOrConfig, unmountedFun)
29
+ }
30
+
31
+ /**
32
+ * @function publishProject
33
+ * @param {?object} { cache = false, all = false }
34
+ */
35
+ export function publishProject({ cache = false, all = false } = {}) {
36
+ const project = getProject()
37
+
38
+ if (all) {
39
+ cachePublish(project)
40
+ projectPublish(project)
41
+ return
42
+ }
43
+
44
+ if (cache) {
45
+ cachePublish(project)
46
+ } else {
47
+ projectPublish(project)
48
+ }
49
+ }
50
+
51
+
52
+
53
+ function isValidId(id) {
54
+ return id !== '' && id !== 'null'
55
+ }
56
+
57
+ // 项目/应用/工作空间
58
+ export function storeProject(projectId = '', rest) {
59
+ if (isObject(rest)) {
60
+ const { teamId, projectName, orgName = '', name = '', ..._rest } = rest
61
+ Object.assign(_currentProject, { id: projectId, projectId, teamId, projectName: projectName || name || orgName, ..._rest })
62
+ } else {
63
+ Object.assign(_currentProject, { id: projectId, projectId })
64
+ }
65
+
66
+ storage.appendObject(KEY, _currentProject)
67
+ _isCleared = false
68
+ }
69
+
70
+ export function getProject() {
71
+ if (_currentProject.projectId !== null || _isCleared) return { ..._currentProject }
72
+
73
+ const { projectId = '', rest } = storage.getObject(KEY)
74
+ Object.assign(_currentProject, { ...rest })
75
+ isValidId(projectId) && Object.assign(_currentProject, { projectId })
76
+ return { ..._currentProject }
77
+ }
78
+
79
+ export function getProjectId() {
80
+ return getProject().projectId;
81
+ }
82
+
83
+
84
+ export function clearProjectData({ stayStored = false } = {}) {
85
+ _isCleared = true
86
+ _currentProject = { ...DEFALUT_CURRENT_PROJECT }
87
+
88
+ if (!stayStored) {
89
+ storage.remove(KEY)
90
+ }
91
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bdlite/domains",
3
- "version": "1.1.28",
3
+ "version": "1.1.30",
4
4
  "description": "A domains entity collection library driven by @bdlite/observable",
5
5
  "keywords": [
6
6
  "DDD",
@@ -25,7 +25,7 @@
25
25
  "@bdlite/strategy": "^1.1.25"
26
26
  },
27
27
  "dependencies": {
28
- "@bdlite/helpers": "^1.1.25",
28
+ "@bdlite/helpers": "^1.1.26",
29
29
  "@bdlite/observable": "^1.1.25",
30
30
  "@bdlite/strategy": "^1.1.25"
31
31
  },
@@ -1,11 +0,0 @@
1
- import { createSubChannelKit } from '@bdlite/observable/es/create-observable-kit'
2
- import { CHANNEL_NAME, MENU_CHANNEL_NAME, MENU_ITEM_CHANNEL_NAME } from './constants'
3
-
4
- const obOptions = { relay: 1 }
5
- const layoutChannel = createSubChannelKit({ channelName: CHANNEL_NAME }, obOptions)
6
- const menuChannel = createSubChannelKit({ channelName: MENU_CHANNEL_NAME }, obOptions)
7
- const menuItemChannel = createSubChannelKit({ channelName: MENU_ITEM_CHANNEL_NAME }, obOptions)
8
-
9
- export const subscribeLayout = layoutChannel.subscribe
10
- export const subscribeMenu = menuChannel.subscribe
11
- export const subscribeMenuItem = menuItemChannel.subscribe