dsh-paste-code-block 0.1.0 → 0.1.2
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 +63 -29
- package/README.zh-CN.md +61 -31
- package/docs/design.md +112 -9
- package/docs/images/hero.png +0 -0
- package/docs/images/hero.svg +4 -0
- package/docs/images/languages.png +0 -0
- package/docs/images/languages.svg +4 -0
- package/docs/images/workflow.png +0 -0
- package/docs/images/workflow.svg +4 -0
- package/package.json +19 -4
- package/src/chip-nodes.js +46 -0
- package/src/client.js +470 -53
- package/src/i18n.js +111 -0
- package/src/parse.js +3 -2
- package/src/projection.js +54 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chip-node helpers for the composer editor.
|
|
3
|
+
*
|
|
4
|
+
* DSH renders each reference (our pasted block) as a Lexical decorator chip.
|
|
5
|
+
* The input shell exposes no per-reference delete verb, so removal reaches the
|
|
6
|
+
* node map (`editor.getEditorState()._nodeMap`) and drops the matching node.
|
|
7
|
+
*
|
|
8
|
+
* The node map is keyed by NodeKey and its VALUES ARE THE NODES THEMSELVES
|
|
9
|
+
* (Lexical >= 0.21, verified against 0.49.0 by tests/lexical-chip-probe.mjs).
|
|
10
|
+
* The older `NodeState` wrapper with a `.node` field is gone, so reading
|
|
11
|
+
* `value.node` yields undefined for every entry — which is exactly how v0.1.2's
|
|
12
|
+
* delete turned into a silent no-op instead of deleting the block.
|
|
13
|
+
*
|
|
14
|
+
* Pure and dependency-free so the shape rule is unit-testable; keep the
|
|
15
|
+
* embedded copy in src/client.js in sync (same rule as parse.js/i18n.js).
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Normalize one node-map value to a chip-like node.
|
|
20
|
+
* @param value - raw node-map value (a node, or a legacy NodeState wrapper).
|
|
21
|
+
* @returns the node when it exposes the chip accessors, else null.
|
|
22
|
+
*/
|
|
23
|
+
export function chipNodeOf(value) {
|
|
24
|
+
if (!value) return null
|
|
25
|
+
if (typeof value.getSource === 'function') return value
|
|
26
|
+
const wrapped = value.node
|
|
27
|
+
return wrapped && typeof wrapped.getSource === 'function' ? wrapped : null
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Collect the chip node(s) belonging to one source + ref.
|
|
32
|
+
* @param values - node-map values (`map.values()`).
|
|
33
|
+
* @param source - owning reference source (e.g. 'paste-code-block').
|
|
34
|
+
* @param ref - owner-scoped reference id (the block id).
|
|
35
|
+
* @returns matching nodes, in map order (usually exactly one).
|
|
36
|
+
*/
|
|
37
|
+
export function collectChipNodes(values, source, ref) {
|
|
38
|
+
const hits = []
|
|
39
|
+
if (!values) return hits
|
|
40
|
+
for (const value of values) {
|
|
41
|
+
const node = chipNodeOf(value)
|
|
42
|
+
if (!node || typeof node.getReference !== 'function') continue
|
|
43
|
+
if (node.getSource() === source && node.getReference() === ref) hits.push(node)
|
|
44
|
+
}
|
|
45
|
+
return hits
|
|
46
|
+
}
|