@lvce-editor/embeds-process 1.4.0 → 1.5.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/embeds-process",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "",
5
5
  "main": "src/embedsProcessMain.js",
6
6
  "type": "module",
@@ -51,6 +51,7 @@
51
51
  ]
52
52
  },
53
53
  "dependencies": {
54
+ "@lvce-editor/assert": "^1.2.0",
54
55
  "@lvce-editor/ipc": "^9.1.0",
55
56
  "@lvce-editor/json-rpc": "^1.3.0"
56
57
  }
@@ -1,94 +1 @@
1
- // TODO treeshake out this whole module in production
2
-
3
- import { AssertionError } from '../AssertionError/AssertionError.js'
4
-
5
- const getType = (value) => {
6
- switch (typeof value) {
7
- case 'number':
8
- return 'number'
9
- case 'function':
10
- return 'function'
11
- case 'string':
12
- return 'string'
13
- case 'object':
14
- if (value === null) {
15
- return 'null'
16
- }
17
- if (Array.isArray(value)) {
18
- return 'array'
19
- }
20
- if (value instanceof Uint32Array) {
21
- return 'uint32array'
22
- }
23
- return 'object'
24
- case 'boolean':
25
- return 'boolean'
26
- default:
27
- return 'unknown'
28
- }
29
- }
30
-
31
- export const object = (value) => {
32
- const type = getType(value)
33
- if (type !== 'object') {
34
- throw new AssertionError('expected value to be of type object')
35
- }
36
- }
37
-
38
- export const number = (value) => {
39
- const type = getType(value)
40
- if (type !== 'number') {
41
- throw new AssertionError('expected value to be of type number')
42
- }
43
- if (isNaN(value)) {
44
- throw new AssertionError('value is NaN')
45
- }
46
- }
47
-
48
- export const array = (value) => {
49
- const type = getType(value)
50
- if (type !== 'array') {
51
- throw new AssertionError('expected value to be of type array')
52
- }
53
- }
54
-
55
- export const string = (value) => {
56
- const type = getType(value)
57
- if (type !== 'string') {
58
- throw new AssertionError('expected value to be of type string')
59
- }
60
- }
61
-
62
- export const null_ = (value) => {
63
- const type = getType(value)
64
- if (type !== 'null') {
65
- throw new AssertionError('expected value to be of type null')
66
- }
67
- }
68
-
69
- export const boolean = (value) => {
70
- const type = getType(value)
71
- if (type !== 'boolean') {
72
- throw new AssertionError('expected value to be of type boolean')
73
- }
74
- }
75
-
76
- export const fn = (value) => {
77
- const type = getType(value)
78
- if (type !== 'function') {
79
- throw new AssertionError('expected value to be of type function')
80
- }
81
- }
82
-
83
- export const uint32array = (value) => {
84
- const type = getType(value)
85
- if (type !== 'uint32array') {
86
- throw new AssertionError('expected value to be of type uint32array')
87
- }
88
- }
89
-
90
- export const greaterZero = (value) => {
91
- if (value <= 0) {
92
- throw new Error('value must be greater than zero')
93
- }
94
- }
1
+ export * from '@lvce-editor/assert'
@@ -1,9 +1,7 @@
1
- export const state = {
2
- commands: Object.create(null),
3
- }
1
+ const commands = Object.create(null)
4
2
 
5
3
  export const registerCommand = (key, fn) => {
6
- state.commands[key] = fn
4
+ commands[key] = fn
7
5
  }
8
6
 
9
7
  export const registerCommands = (commandMap) => {
@@ -13,5 +11,11 @@ export const registerCommands = (commandMap) => {
13
11
  }
14
12
 
15
13
  export const getCommand = (key) => {
16
- return state.commands[key]
14
+ return commands[key]
15
+ }
16
+
17
+ export const reset = () => {
18
+ for (const key of Object.keys(commands)) {
19
+ delete commands[key]
20
+ }
17
21
  }
@@ -1,5 +1,5 @@
1
- import * as ElectronBrowserViewIpcState from '../ElectronWebContentsViewIpcState/ElectronWebContentsViewIpcState.js'
2
- import * as ElectronBrowserViewState from '../ElectronBrowserViewState/ElectronBrowserViewState.js'
1
+ import * as ElectronWebContentsViewIpcState from '../ElectronWebContentsViewIpcState/ElectronWebContentsViewIpcState.js'
2
+ import * as ElectronWebContentsViewState from '../ElectronWebContentsViewState/ElectronWebContentsViewState.js'
3
3
  import * as ParentIpc from '../ParentIpc/ParentIpc.js'
4
4
 
5
5
  export const dispose = async (id) => {
@@ -39,7 +39,7 @@ export const handleWindowOpen = (webContentsId, url) => {
39
39
  }
40
40
 
41
41
  const forwardEvent = (method, webContentsId, ...params) => {
42
- const ipc = ElectronBrowserViewIpcState.get(webContentsId)
42
+ const ipc = ElectronWebContentsViewIpcState.get(webContentsId)
43
43
  if (!ipc) {
44
44
  console.log(`[shared-process] no ipc for webcontents ${webContentsId}`)
45
45
  return
@@ -71,7 +71,7 @@ export const handleKeyBinding = (...args) => {
71
71
  forwardEvent('handleKeyBinding', ...args)
72
72
  }
73
73
 
74
- export const handleBrowserViewDestroyed = (id) => {
75
- ElectronBrowserViewState.remove(id)
76
- ElectronBrowserViewIpcState.remove(id)
74
+ export const handleWebContentsViewDestroyed = (id) => {
75
+ ElectronWebContentsViewState.remove(id)
76
+ ElectronWebContentsViewIpcState.remove(id)
77
77
  }
@@ -0,0 +1,13 @@
1
+ const webContentViews = Object.create(null)
2
+
3
+ export const add = (id) => {
4
+ webContentViews[id] = id
5
+ }
6
+
7
+ export const remove = (id) => {
8
+ delete webContentViews[id]
9
+ }
10
+
11
+ export const getAll = () => {
12
+ return Object.values(webContentViews)
13
+ }
@@ -5,6 +5,7 @@ import * as SharedProcessIpc from '../SharedProcessIpc/SharedProcessIpc.js'
5
5
 
6
6
  export const targetMessagePort = async (messagePort, message) => {
7
7
  Assert.object(messagePort)
8
+ // TODO don't listen directly, return type 'listen' and type 'set' with parameters
8
9
  const ipc = await IpcChild.listen({
9
10
  method: IpcChildType.ElectronMessagePort,
10
11
  messagePort,
@@ -1,6 +0,0 @@
1
- export class AssertionError extends Error {
2
- constructor(message) {
3
- super(message)
4
- this.name = 'AssertionError'
5
- }
6
- }
@@ -1,15 +0,0 @@
1
- const state = {
2
- browserViews: Object.create(null),
3
- }
4
-
5
- export const add = (id) => {
6
- state.browserViews[id] = id
7
- }
8
-
9
- export const remove = (id) => {
10
- delete state.browserViews[id]
11
- }
12
-
13
- export const getAll = () => {
14
- return Object.values(state.browserViews)
15
- }