@norio-office/rich-text 0.1.0 → 0.3.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/README.md +1147 -971
- package/dist/{chunk-efA98nb6.js → chunk-C_CI6nMA.js} +1 -1
- package/dist/components/OutlinePanel.vue.d.ts +22 -11
- package/dist/components/RichTextEditor.vue.d.ts +25 -1
- package/dist/components/RichTextOutline.vue.d.ts +30 -0
- package/dist/composables/useRichTextEditor.d.ts +7 -2
- package/dist/extensions/image-block.d.ts +7 -1
- package/dist/extensions/video-block.d.ts +7 -1
- package/dist/{html2canvas-Bwmq6fGh.js → html2canvas-CmV4ppBE.js} +2 -2
- package/dist/index.d.ts +3 -2
- package/dist/{index.es-C4X5YiRo.js → index.es-D5dDjrL4.js} +1 -1
- package/dist/index.js +5513 -4766
- package/dist/index.umd.cjs +871 -589
- package/dist/{jspdf.es.min-ByaXFVjc.js → jspdf.es.min-B2a2-__Q.js} +17 -17
- package/dist/purify.es-jA1o6Tcu.js +597 -0
- package/dist/style.css +1 -1
- package/dist/types.d.ts +58 -24
- package/dist/utils/url.d.ts +2 -0
- package/docs/usage.md +66 -95
- package/package.json +2 -8
- package/dist/purify.es-B5ixYH9L.js +0 -549
- package/yjs/README.md +0 -63
- package/yjs/index.js +0 -224
- package/yjs/package.json +0 -14
package/yjs/index.js
DELETED
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
import http from 'node:http'
|
|
2
|
-
|
|
3
|
-
import * as decoding from 'lib0/decoding'
|
|
4
|
-
import * as encoding from 'lib0/encoding'
|
|
5
|
-
import * as awarenessProtocol from 'y-protocols/awareness'
|
|
6
|
-
import * as syncProtocol from 'y-protocols/sync'
|
|
7
|
-
import WebSocket, { WebSocketServer } from 'ws'
|
|
8
|
-
import * as Y from 'yjs'
|
|
9
|
-
|
|
10
|
-
const host = process.env.HOST || '0.0.0.0'
|
|
11
|
-
const port = Number(process.env.PORT || 1234)
|
|
12
|
-
|
|
13
|
-
const messageSync = 0
|
|
14
|
-
const messageAwareness = 1
|
|
15
|
-
const pingTimeout = 30000
|
|
16
|
-
|
|
17
|
-
const docs = new Map()
|
|
18
|
-
|
|
19
|
-
function getDoc(name) {
|
|
20
|
-
const existing = docs.get(name)
|
|
21
|
-
if (existing) {
|
|
22
|
-
return existing
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const doc = new Y.Doc()
|
|
26
|
-
const awareness = new awarenessProtocol.Awareness(doc)
|
|
27
|
-
const conns = new Map()
|
|
28
|
-
|
|
29
|
-
awareness.setLocalState(null)
|
|
30
|
-
|
|
31
|
-
doc.on('update', (update) => {
|
|
32
|
-
const encoder = encoding.createEncoder()
|
|
33
|
-
encoding.writeVarUint(encoder, messageSync)
|
|
34
|
-
syncProtocol.writeUpdate(encoder, update)
|
|
35
|
-
const message = encoding.toUint8Array(encoder)
|
|
36
|
-
|
|
37
|
-
conns.forEach((_, conn) => {
|
|
38
|
-
send(conn, message)
|
|
39
|
-
})
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
awareness.on('update', ({ added, updated, removed }, conn) => {
|
|
43
|
-
const changedClients = added.concat(updated, removed)
|
|
44
|
-
|
|
45
|
-
if (conn) {
|
|
46
|
-
const controlledIds = conns.get(conn)
|
|
47
|
-
if (controlledIds) {
|
|
48
|
-
added.forEach((id) => controlledIds.add(id))
|
|
49
|
-
removed.forEach((id) => controlledIds.delete(id))
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const encoder = encoding.createEncoder()
|
|
54
|
-
encoding.writeVarUint(encoder, messageAwareness)
|
|
55
|
-
encoding.writeVarUint8Array(
|
|
56
|
-
encoder,
|
|
57
|
-
awarenessProtocol.encodeAwarenessUpdate(awareness, changedClients),
|
|
58
|
-
)
|
|
59
|
-
|
|
60
|
-
const message = encoding.toUint8Array(encoder)
|
|
61
|
-
conns.forEach((_, ws) => {
|
|
62
|
-
send(ws, message)
|
|
63
|
-
})
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
const entry = { name, doc, awareness, conns }
|
|
67
|
-
docs.set(name, entry)
|
|
68
|
-
return entry
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function removeDocIfEmpty(entry) {
|
|
72
|
-
if (entry.conns.size === 0) {
|
|
73
|
-
entry.doc.destroy()
|
|
74
|
-
docs.delete(entry.name)
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function closeConn(entry, conn) {
|
|
79
|
-
const controlledIds = entry.conns.get(conn)
|
|
80
|
-
|
|
81
|
-
if (controlledIds) {
|
|
82
|
-
entry.conns.delete(conn)
|
|
83
|
-
awarenessProtocol.removeAwarenessStates(
|
|
84
|
-
entry.awareness,
|
|
85
|
-
Array.from(controlledIds),
|
|
86
|
-
null,
|
|
87
|
-
)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
try {
|
|
91
|
-
conn.close()
|
|
92
|
-
} catch {
|
|
93
|
-
// ignore close failures
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
removeDocIfEmpty(entry)
|
|
97
|
-
console.log(`[disconnect] room=${entry.name} clients=${entry.conns.size}`)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function send(conn, message) {
|
|
101
|
-
if (conn.readyState !== WebSocket.OPEN && conn.readyState !== WebSocket.CONNECTING) {
|
|
102
|
-
try {
|
|
103
|
-
conn.close()
|
|
104
|
-
} catch {
|
|
105
|
-
// ignore close failures
|
|
106
|
-
}
|
|
107
|
-
return
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
conn.send(message, (error) => {
|
|
111
|
-
if (error) {
|
|
112
|
-
try {
|
|
113
|
-
conn.close()
|
|
114
|
-
} catch {
|
|
115
|
-
// ignore close failures
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
})
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function setupWSConnection(conn, req) {
|
|
122
|
-
const docName = (req.url || '/').slice(1).split('?')[0] || 'default'
|
|
123
|
-
const entry = getDoc(docName)
|
|
124
|
-
|
|
125
|
-
entry.conns.set(conn, new Set())
|
|
126
|
-
conn.binaryType = 'arraybuffer'
|
|
127
|
-
|
|
128
|
-
conn.on('message', (message) => {
|
|
129
|
-
try {
|
|
130
|
-
const decoder = decoding.createDecoder(new Uint8Array(message))
|
|
131
|
-
const encoder = encoding.createEncoder()
|
|
132
|
-
const messageType = decoding.readVarUint(decoder)
|
|
133
|
-
|
|
134
|
-
switch (messageType) {
|
|
135
|
-
case messageSync:
|
|
136
|
-
encoding.writeVarUint(encoder, messageSync)
|
|
137
|
-
syncProtocol.readSyncMessage(decoder, encoder, entry.doc, conn)
|
|
138
|
-
if (encoding.length(encoder) > 1) {
|
|
139
|
-
send(conn, encoding.toUint8Array(encoder))
|
|
140
|
-
}
|
|
141
|
-
break
|
|
142
|
-
case messageAwareness:
|
|
143
|
-
awarenessProtocol.applyAwarenessUpdate(
|
|
144
|
-
entry.awareness,
|
|
145
|
-
decoding.readVarUint8Array(decoder),
|
|
146
|
-
conn,
|
|
147
|
-
)
|
|
148
|
-
break
|
|
149
|
-
default:
|
|
150
|
-
break
|
|
151
|
-
}
|
|
152
|
-
} catch (error) {
|
|
153
|
-
console.error('[message-error]', error)
|
|
154
|
-
}
|
|
155
|
-
})
|
|
156
|
-
|
|
157
|
-
let pongReceived = true
|
|
158
|
-
const pingInterval = setInterval(() => {
|
|
159
|
-
if (!pongReceived) {
|
|
160
|
-
clearInterval(pingInterval)
|
|
161
|
-
closeConn(entry, conn)
|
|
162
|
-
return
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
pongReceived = false
|
|
166
|
-
try {
|
|
167
|
-
conn.ping()
|
|
168
|
-
} catch {
|
|
169
|
-
clearInterval(pingInterval)
|
|
170
|
-
closeConn(entry, conn)
|
|
171
|
-
}
|
|
172
|
-
}, pingTimeout)
|
|
173
|
-
|
|
174
|
-
conn.on('pong', () => {
|
|
175
|
-
pongReceived = true
|
|
176
|
-
})
|
|
177
|
-
|
|
178
|
-
conn.on('close', () => {
|
|
179
|
-
clearInterval(pingInterval)
|
|
180
|
-
closeConn(entry, conn)
|
|
181
|
-
})
|
|
182
|
-
|
|
183
|
-
conn.on('error', (error) => {
|
|
184
|
-
console.error('[socket-error]', error)
|
|
185
|
-
})
|
|
186
|
-
|
|
187
|
-
const syncEncoder = encoding.createEncoder()
|
|
188
|
-
encoding.writeVarUint(syncEncoder, messageSync)
|
|
189
|
-
syncProtocol.writeSyncStep1(syncEncoder, entry.doc)
|
|
190
|
-
send(conn, encoding.toUint8Array(syncEncoder))
|
|
191
|
-
|
|
192
|
-
const awarenessStates = entry.awareness.getStates()
|
|
193
|
-
if (awarenessStates.size > 0) {
|
|
194
|
-
const awarenessEncoder = encoding.createEncoder()
|
|
195
|
-
encoding.writeVarUint(awarenessEncoder, messageAwareness)
|
|
196
|
-
encoding.writeVarUint8Array(
|
|
197
|
-
awarenessEncoder,
|
|
198
|
-
awarenessProtocol.encodeAwarenessUpdate(
|
|
199
|
-
entry.awareness,
|
|
200
|
-
Array.from(awarenessStates.keys()),
|
|
201
|
-
),
|
|
202
|
-
)
|
|
203
|
-
send(conn, encoding.toUint8Array(awarenessEncoder))
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
console.log(`[connect] room=${docName} clients=${entry.conns.size}`)
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
const server = http.createServer((_req, res) => {
|
|
210
|
-
res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' })
|
|
211
|
-
res.end('ok')
|
|
212
|
-
})
|
|
213
|
-
|
|
214
|
-
const wss = new WebSocketServer({ noServer: true })
|
|
215
|
-
|
|
216
|
-
server.on('upgrade', (request, socket, head) => {
|
|
217
|
-
wss.handleUpgrade(request, socket, head, (ws) => {
|
|
218
|
-
setupWSConnection(ws, request)
|
|
219
|
-
})
|
|
220
|
-
})
|
|
221
|
-
|
|
222
|
-
server.listen(port, host, () => {
|
|
223
|
-
console.log(`yjs websocket server running at ws://${host}:${port}`)
|
|
224
|
-
})
|
package/yjs/package.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@norio-office/rich-text-yjs-server",
|
|
3
|
-
"private": true,
|
|
4
|
-
"type": "module",
|
|
5
|
-
"scripts": {
|
|
6
|
-
"start": "node index.js"
|
|
7
|
-
},
|
|
8
|
-
"dependencies": {
|
|
9
|
-
"lib0": "^0.2.102",
|
|
10
|
-
"ws": "^8.18.0",
|
|
11
|
-
"y-protocols": "^1.0.6",
|
|
12
|
-
"yjs": "^13.6.30"
|
|
13
|
-
}
|
|
14
|
-
}
|