@lvce-editor/shared-process 0.0.37 → 0.0.40

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.
@@ -1,33 +1,122 @@
1
+ /**
2
+ * @enum number
3
+ */
4
+ export const State = {
5
+ TopLevelContent: 1,
6
+ InsideLineComment: 2,
7
+ }
8
+
9
+ export const StateMap = {
10
+ [State.TopLevelContent]: 'TopLevelContent',
11
+ [State.InsideLineComment]: 'InsideLineComment',
12
+ }
13
+
1
14
  /**
2
15
  * @enum number
3
16
  */
4
17
  export const TokenType = {
5
- Text: 0,
6
- NewLine: 1,
18
+ CssSelector: 1,
19
+ Whitespace: 2,
20
+ None: 57,
21
+ Unknown: 881,
22
+ NewLine: 884,
23
+ Comment: 885,
24
+ Query: 886,
25
+ Text: 887,
7
26
  }
8
27
 
9
28
  export const TokenMap = {
29
+ [TokenType.CssSelector]: 'CssSelector',
30
+ [TokenType.Whitespace]: 'Whitespace',
31
+ [TokenType.None]: 'None',
32
+ [TokenType.Unknown]: 'Unknown',
33
+ [TokenType.NewLine]: 'NewLine',
34
+ [TokenType.Comment]: 'Comment',
35
+ [TokenType.Query]: 'Query',
10
36
  [TokenType.Text]: 'Text',
11
37
  }
12
38
 
39
+ const RE_LINE_COMMENT_START = /^#/
40
+ const RE_WHITESPACE = /^ +/
41
+ const RE_CURLY_OPEN = /^\{/
42
+ const RE_CURLY_CLOSE = /^\}/
43
+ const RE_PROPERTY_NAME = /^[a-zA-Z\-]+\b/
44
+ const RE_COLON = /^:/
45
+ const RE_PROPERTY_VALUE = /^[^;\}]+/
46
+ const RE_SEMICOLON = /^;/
47
+ const RE_COMMA = /^,/
48
+ const RE_ANYTHING = /^.*/
49
+ const RE_NUMERIC = /^(([0-9]+\.?[0-9]*)|(\.[0-9]+))/
50
+ const RE_ANYTHING_UNTIL_CLOSE_BRACE = /^[^\}]+/
51
+ const RE_BLOCK_COMMENT_START = /^\/\*/
52
+ const RE_BLOCK_COMMENT_END = /^\*\//
53
+ const RE_BLOCK_COMMENT_CONTENT = /^.+?(?=\*\/|$)/s
54
+ const RE_ROUND_OPEN = /^\(/
55
+ const RE_ROUND_CLOSE = /^\)/
56
+ const RE_PSEUDO_SELECTOR_CONTENT = /^[^\)]+/
57
+ const RE_SQUARE_OPEN = /^\[/
58
+ const RE_SQUARE_CLOSE = /^\]/
59
+ const RE_ATTRIBUTE_SELECTOR_CONTENT = /^[^\]]+/
60
+ const RE_QUERY = /^@[a-z\-]+/
61
+ const RE_STAR = /^\*/
62
+ const RE_QUERY_NAME = /^[a-z\-]+/
63
+ const RE_QUERY_CONTENT = /^[^\)]+/
64
+ const RE_COMBINATOR = /^[\+\>\~]/
65
+
13
66
  export const initialLineState = {
14
- state: 1,
67
+ state: State.TopLevelContent,
68
+ tokens: [],
69
+ stack: [],
15
70
  }
16
71
 
72
+ /**
73
+ * @param {string} line
74
+ * @param {any} lineState
75
+ */
17
76
  export const tokenizeLine = (line, lineState) => {
18
- if (line.length === 0) {
19
- return {
20
- state: 1,
21
- tokens: [],
77
+ let next = null
78
+ let index = 0
79
+ let tokens = []
80
+ let token = TokenType.None
81
+ let state = lineState.state
82
+ while (index < line.length) {
83
+ const part = line.slice(index)
84
+ switch (state) {
85
+ case State.TopLevelContent:
86
+ if ((next = part.match(RE_LINE_COMMENT_START))) {
87
+ token = TokenType.Comment
88
+ state = State.InsideLineComment
89
+ } else if ((next = part.match(RE_WHITESPACE))) {
90
+ token = TokenType.Whitespace
91
+ state = State.TopLevelContent
92
+ } else if ((next = part.match(RE_ANYTHING))) {
93
+ token = TokenType.Text
94
+ state = State.TopLevelContent
95
+ } else {
96
+ part //?
97
+ throw new Error('no')
98
+ }
99
+ break
100
+ case State.InsideLineComment:
101
+ if ((next = part.match(RE_ANYTHING))) {
102
+ token = TokenType.Comment
103
+ state = State.TopLevelContent
104
+ } else {
105
+ throw new Error('no')
106
+ }
107
+ break
108
+ default:
109
+ console.log({ state, line })
110
+ throw new Error('no')
22
111
  }
112
+ index += next[0].length
113
+ tokens.push({
114
+ type: token,
115
+ length: next[0].length,
116
+ })
23
117
  }
24
118
  return {
25
- state: 1,
26
- tokens: [
27
- {
28
- type: TokenType.Text,
29
- length: line.length,
30
- },
31
- ],
119
+ state,
120
+ tokens,
32
121
  }
33
122
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/shared-process",
3
- "version": "0.0.37",
3
+ "version": "0.0.40",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -38,8 +38,8 @@
38
38
  "verror": "^1.10.1",
39
39
  "ws": "^8.8.1",
40
40
  "xdg-basedir": "^5.1.0",
41
- "@lvce-editor/pty-host": "0.0.37",
42
- "@lvce-editor/extension-host": "0.0.37"
41
+ "@lvce-editor/pty-host": "0.0.40",
42
+ "@lvce-editor/extension-host": "0.0.40"
43
43
  },
44
44
  "optionalDependencies": {
45
45
  "electron-clipboard-ex": "^1.3.3",
@@ -65,10 +65,11 @@ export const about = async () => {
65
65
  await invoke(/* About.open */ 'About.open')
66
66
  }
67
67
 
68
- export const showOpenDialog = async (title) => {
68
+ export const showOpenDialog = async (title, properties) => {
69
69
  const result = await invoke(
70
70
  /* Dialog.showOpenDialog */ 'Dialog.showOpenDialog',
71
- /* title */ title
71
+ /* title */ title,
72
+ /* properties */ properties
72
73
  )
73
74
  return result
74
75
  }
@@ -32,40 +32,6 @@ const getEnabledExtensionWithOnlyExtension = (
32
32
  return extensions
33
33
  }
34
34
 
35
- export const state = {
36
- async getExtensions() {
37
- // TODO only read from env once
38
- const builtinExtensions = await getBuiltinExtensions()
39
- const onlyExtensionPath = Platform.getOnlyExtensionPath()
40
- if (onlyExtensionPath) {
41
- const absolutePath = path.resolve(onlyExtensionPath)
42
- const [onlyExtension] = await getExtensionManifests([absolutePath])
43
- const enabledExtensions = getEnabledExtensionWithOnlyExtension(
44
- builtinExtensions,
45
- onlyExtension
46
- )
47
- return enabledExtensions
48
- }
49
- const installedExtensions = await getInstalledExtensions()
50
- return [...builtinExtensions, ...installedExtensions]
51
- },
52
- async getThemeExtensions() {
53
- const builtinExtensionsPath = Platform.getBuiltinExtensionsPath()
54
- const dirents = await readdir(builtinExtensionsPath)
55
- const paths = []
56
- for (const dirent of dirents) {
57
- if (isTheme(dirent)) {
58
- paths.push(getAbsoluteBuiltinExtensionPath(dirent))
59
- }
60
- }
61
- if (process.env.ONLY_EXTENSION && isTheme(process.env.ONLY_EXTENSION)) {
62
- paths.push(process.env.ONLY_EXTENSION)
63
- }
64
- const builtinExtensions = await getExtensionManifests(paths)
65
- return builtinExtensions
66
- },
67
- }
68
-
69
35
  export const install = async (id) => {
70
36
  // TODO this should be a stateless function, renderer-worker should have info on marketplace url
71
37
  // TODO use command.execute
@@ -301,7 +267,20 @@ export const getInstalledExtensions = async () => {
301
267
  }
302
268
 
303
269
  export const getExtensions = async () => {
304
- return state.getExtensions()
270
+ // TODO only read from env once
271
+ const builtinExtensions = await getBuiltinExtensions()
272
+ const onlyExtensionPath = Platform.getOnlyExtensionPath()
273
+ if (onlyExtensionPath) {
274
+ const absolutePath = path.resolve(onlyExtensionPath)
275
+ const [onlyExtension] = await getExtensionManifests([absolutePath])
276
+ const enabledExtensions = getEnabledExtensionWithOnlyExtension(
277
+ builtinExtensions,
278
+ onlyExtension
279
+ )
280
+ return enabledExtensions
281
+ }
282
+ const installedExtensions = await getInstalledExtensions()
283
+ return [...builtinExtensions, ...installedExtensions]
305
284
  }
306
285
 
307
286
  const RE_THEME = /[a-z]+\.[a-z\-]*theme-[a-z\d\-]+$/
@@ -317,7 +296,20 @@ const getThemeExtensionsBuiltin = async () => {
317
296
  }
318
297
 
319
298
  export const getThemeExtensions = async () => {
320
- return state.getThemeExtensions()
299
+ const builtinExtensionsPath = Platform.getBuiltinExtensionsPath()
300
+ const dirents = await readdir(builtinExtensionsPath)
301
+ const paths = []
302
+ for (const dirent of dirents) {
303
+ if (isTheme(dirent)) {
304
+ paths.push(getAbsoluteBuiltinExtensionPath(dirent))
305
+ }
306
+ }
307
+ const onlyExtensionPath = Platform.getOnlyExtensionPath()
308
+ if (onlyExtensionPath && isTheme(onlyExtensionPath)) {
309
+ paths.push(onlyExtensionPath)
310
+ }
311
+ const builtinExtensions = await getExtensionManifests(paths)
312
+ return builtinExtensions
321
313
  }
322
314
 
323
315
  export const getDisabledExtensions = async () => {
@@ -327,8 +319,9 @@ export const getDisabledExtensions = async () => {
327
319
  }
328
320
 
329
321
  export const getAllExtensions = async () => {
330
- if (process.env.ONLY_EXTENSION) {
331
- return getExtensionManifests([process.env.ONLY_EXTENSION])
322
+ const onlyExtensionPath = Platform.getOnlyExtensionPath()
323
+ if (onlyExtensionPath) {
324
+ return getExtensionManifests([onlyExtensionPath])
332
325
  }
333
326
  const t1 = performance.now()
334
327
  const [builtinExtensions, installedExtensions, disabledExtensions] =