Skip to content

Commit 5f661bf

Browse files
Merge branch 'develop' of https://github.com/hcengineering/platform into staging-new
Signed-off-by: Artem Savchenko <[email protected]>
2 parents 35aeae1 + 7681ccb commit 5f661bf

File tree

14 files changed

+304
-139
lines changed

14 files changed

+304
-139
lines changed

common/config/rush/pnpm-lock.yaml

Lines changed: 21 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

desktop/src/ui/preload.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// preload.js
22

33
import { contextBridge, ipcRenderer } from 'electron'
4-
import { BrandingMap, Config, IPCMainExposed, MenuBarAction, NotificationParams, JumpListSpares } from './types'
4+
import { BrandingMap, Config, IPCMainExposed, JumpListSpares, MenuBarAction, NotificationParams } from './types'
55

66
/**
77
* @public
@@ -18,27 +18,23 @@ export function concatLink (host: string, path: string): string {
1818
}
1919

2020
async function loadServerConfig (url: string): Promise<any> {
21-
let retries = 5
21+
let retries = 1
2222
let res: Response | undefined
2323

24-
do {
24+
while (true) {
2525
try {
2626
res = await fetch(url, {
2727
keepalive: true
2828
})
29+
if (res === undefined) {
30+
// In theory should never get here
31+
throw new Error('Failed to load server config')
32+
}
2933
break
3034
} catch (e) {
31-
retries--
32-
if (retries === 0) {
33-
throw new Error(`Failed to load server config: ${e}`)
34-
}
35-
await new Promise((resolve) => setTimeout(resolve, 1000 * (5 - retries)))
35+
retries++
36+
await new Promise((resolve) => setTimeout(resolve, 1000 * Math.min(5, retries)))
3637
}
37-
} while (retries > 0)
38-
39-
if (res === undefined) {
40-
// In theory should never get here
41-
throw new Error('Failed to load server config')
4238
}
4339

4440
return await res.json()

packages/text-core/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
},
4141
"dependencies": {
4242
"@hcengineering/core": "^0.6.32",
43-
"fast-equals": "^5.2.2"
43+
"fast-equals": "^5.2.2",
44+
"hash-it": "^6.0.0"
4445
},
4546
"repository": "https://github.com/hcengineering/platform",
4647
"publishConfig": {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { hashAttrs, stripHash } from '../utils'
2+
3+
describe('hashAttrs', () => {
4+
it('should return a hash of length 8', () => {
5+
const attrs = { a: 1 }
6+
const hash = hashAttrs(attrs)
7+
expect(hash.length).toEqual(8)
8+
})
9+
it('should return the same hash for the same attrs', () => {
10+
const attrs = { a: 1, b: 2 }
11+
const hash1 = hashAttrs(attrs)
12+
const hash2 = hashAttrs(attrs)
13+
expect(hash1).toEqual(hash2)
14+
})
15+
16+
it('should return different hashes for different attrs', () => {
17+
const attrs1 = { a: 1, b: 2 }
18+
const attrs2 = { a: 1, b: 3 }
19+
const hash1 = hashAttrs(attrs1)
20+
const hash2 = hashAttrs(attrs2)
21+
expect(hash1).not.toEqual(hash2)
22+
})
23+
})
24+
25+
describe('stripHash', () => {
26+
it('should return the name without the hash', () => {
27+
const name = 'bold--c0decafe'
28+
const result = stripHash(name)
29+
expect(result).toEqual('bold')
30+
})
31+
32+
it('should return the original name if no hash is present', () => {
33+
const name = 'bold'
34+
const result = stripHash(name)
35+
expect(result).toEqual(name)
36+
})
37+
38+
it('should return the original name if the hash is not 8 characters long', () => {
39+
const name = 'bold--1234567'
40+
const result = stripHash(name)
41+
expect(result).toEqual(name)
42+
})
43+
44+
it('should return the original name if the hash is not a valid base64 string', () => {
45+
const name = 'bold--invalid!'
46+
const result = stripHash(name)
47+
expect(result).toEqual(name)
48+
})
49+
})

packages/text-core/src/markup/utils.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
import { Markup } from '@hcengineering/core'
1717

1818
import { deepEqual } from 'fast-equals'
19+
import hashIt from 'hash-it'
20+
1921
import { nodeDoc, nodeParagraph, nodeText } from './dsl'
20-
import { MarkupMark, MarkupNode, MarkupNodeType, emptyMarkupNode } from './model'
21-
import { traverseNode } from './traverse'
22+
import { MarkupMark, MarkupMarkType, MarkupNode, MarkupNodeType, emptyMarkupNode } from './model'
23+
import { traverseAllMarks, traverseNode } from './traverse'
2224

2325
/** @public */
2426
export const EmptyMarkup: Markup = jsonToMarkup(emptyMarkupNode())
@@ -124,7 +126,11 @@ export function markupToJSON (markup: Markup): MarkupNode {
124126
// But there seem to be some cases when it contains HTML or plain text
125127
// So we need to handle those cases and produce valid MarkupNode
126128
if (markup.startsWith('{')) {
127-
return JSON.parse(markup) as MarkupNode
129+
const json = JSON.parse(markup) as MarkupNode
130+
traverseAllMarks(json, (node, mark) => {
131+
mark.type = stripHash(mark.type) as MarkupMarkType
132+
})
133+
return json
128134
} else {
129135
return nodeDoc(nodeParagraph(nodeText(markup)))
130136
}
@@ -207,3 +213,17 @@ export function markupToText (markup: Markup): string {
207213

208214
return fragments.join('').trim()
209215
}
216+
217+
// see https://github.com/yjs/y-prosemirror/blob/master/src/lib.js#L402
218+
const hashedMarkNameRegex = /(.*)(--[a-zA-Z0-9+/=]{8})$/
219+
220+
/** @public */
221+
export function stripHash (attrName: string): string {
222+
return hashedMarkNameRegex.exec(attrName)?.[1] ?? attrName
223+
}
224+
225+
/** @public */
226+
export function hashAttrs (attrs: any): string {
227+
const hash = hashIt(attrs)
228+
return (hash >>> 0).toString(16).padStart(8, '0')
229+
}

packages/text-ydoc/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"dependencies": {
4343
"@hcengineering/core": "^0.6.32",
4444
"@hcengineering/text": "^0.6.5",
45+
"@hcengineering/text-core": "^0.6.0",
4546
"yjs": "^13.6.27"
4647
},
4748
"repository": "https://github.com/hcengineering/platform",

0 commit comments

Comments
 (0)