designmockdown 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +126 -2
- package/dist/app/assets/index-CmugGtLS.js +15 -0
- package/dist/app/assets/index-CwhgxL4e.css +1 -0
- package/dist/app/index.html +13 -0
- package/dist/lib/cli.d.ts +11 -0
- package/dist/lib/cli.d.ts.map +1 -0
- package/dist/lib/cli.js +968 -0
- package/dist/lib/cli.js.map +1 -0
- package/dist/lib/collab/client.d.ts +20 -0
- package/dist/lib/collab/client.d.ts.map +1 -0
- package/dist/lib/collab/client.js +126 -0
- package/dist/lib/collab/client.js.map +1 -0
- package/dist/lib/collab/index.d.ts +40 -0
- package/dist/lib/collab/index.d.ts.map +1 -0
- package/dist/lib/collab/index.js +154 -0
- package/dist/lib/collab/index.js.map +1 -0
- package/dist/lib/collab/room.d.ts +111 -0
- package/dist/lib/collab/room.d.ts.map +1 -0
- package/dist/lib/collab/room.js +120 -0
- package/dist/lib/collab/room.js.map +1 -0
- package/dist/lib/collab/ws.d.ts +33 -0
- package/dist/lib/collab/ws.d.ts.map +1 -0
- package/dist/lib/collab/ws.js +191 -0
- package/dist/lib/collab/ws.js.map +1 -0
- package/dist/lib/components/basic.d.ts +8 -0
- package/dist/lib/components/basic.d.ts.map +1 -0
- package/dist/lib/components/basic.js +181 -0
- package/dist/lib/components/basic.js.map +1 -0
- package/dist/lib/components/config.d.ts +26 -0
- package/dist/lib/components/config.d.ts.map +1 -0
- package/dist/lib/components/config.js +94 -0
- package/dist/lib/components/config.js.map +1 -0
- package/dist/lib/components/containers.d.ts +9 -0
- package/dist/lib/components/containers.d.ts.map +1 -0
- package/dist/lib/components/containers.js +102 -0
- package/dist/lib/components/containers.js.map +1 -0
- package/dist/lib/components/controls.d.ts +8 -0
- package/dist/lib/components/controls.d.ts.map +1 -0
- package/dist/lib/components/controls.js +376 -0
- package/dist/lib/components/controls.js.map +1 -0
- package/dist/lib/components/data.d.ts +8 -0
- package/dist/lib/components/data.d.ts.map +1 -0
- package/dist/lib/components/data.js +494 -0
- package/dist/lib/components/data.js.map +1 -0
- package/dist/lib/components/feedback.d.ts +8 -0
- package/dist/lib/components/feedback.d.ts.map +1 -0
- package/dist/lib/components/feedback.js +151 -0
- package/dist/lib/components/feedback.js.map +1 -0
- package/dist/lib/components/icons.d.ts +28 -0
- package/dist/lib/components/icons.d.ts.map +1 -0
- package/dist/lib/components/icons.js +85 -0
- package/dist/lib/components/icons.js.map +1 -0
- package/dist/lib/components/layout.d.ts +10 -0
- package/dist/lib/components/layout.d.ts.map +1 -0
- package/dist/lib/components/layout.js +82 -0
- package/dist/lib/components/layout.js.map +1 -0
- package/dist/lib/components/nav.d.ts +8 -0
- package/dist/lib/components/nav.d.ts.map +1 -0
- package/dist/lib/components/nav.js +216 -0
- package/dist/lib/components/nav.js.map +1 -0
- package/dist/lib/components/plugin.d.ts +27 -0
- package/dist/lib/components/plugin.d.ts.map +1 -0
- package/dist/lib/components/plugin.js +152 -0
- package/dist/lib/components/plugin.js.map +1 -0
- package/dist/lib/components/registry.d.ts +111 -0
- package/dist/lib/components/registry.d.ts.map +1 -0
- package/dist/lib/components/registry.js +375 -0
- package/dist/lib/components/registry.js.map +1 -0
- package/dist/lib/components/types.d.ts +111 -0
- package/dist/lib/components/types.d.ts.map +1 -0
- package/dist/lib/components/types.js +6 -0
- package/dist/lib/components/types.js.map +1 -0
- package/dist/lib/core/anim.d.ts +31 -0
- package/dist/lib/core/anim.d.ts.map +1 -0
- package/dist/lib/core/anim.js +95 -0
- package/dist/lib/core/anim.js.map +1 -0
- package/dist/lib/core/ast.d.ts +174 -0
- package/dist/lib/core/ast.d.ts.map +1 -0
- package/dist/lib/core/ast.js +42 -0
- package/dist/lib/core/ast.js.map +1 -0
- package/dist/lib/core/chart-source.d.ts +37 -0
- package/dist/lib/core/chart-source.d.ts.map +1 -0
- package/dist/lib/core/chart-source.js +125 -0
- package/dist/lib/core/chart-source.js.map +1 -0
- package/dist/lib/core/data.d.ts +32 -0
- package/dist/lib/core/data.d.ts.map +1 -0
- package/dist/lib/core/data.js +150 -0
- package/dist/lib/core/data.js.map +1 -0
- package/dist/lib/core/define.d.ts +16 -0
- package/dist/lib/core/define.d.ts.map +1 -0
- package/dist/lib/core/define.js +232 -0
- package/dist/lib/core/define.js.map +1 -0
- package/dist/lib/core/diagnostics.d.ts +64 -0
- package/dist/lib/core/diagnostics.d.ts.map +1 -0
- package/dist/lib/core/diagnostics.js +62 -0
- package/dist/lib/core/diagnostics.js.map +1 -0
- package/dist/lib/core/errors.d.ts +27 -0
- package/dist/lib/core/errors.d.ts.map +1 -0
- package/dist/lib/core/errors.js +70 -0
- package/dist/lib/core/errors.js.map +1 -0
- package/dist/lib/core/expand.d.ts +21 -0
- package/dist/lib/core/expand.d.ts.map +1 -0
- package/dist/lib/core/expand.js +226 -0
- package/dist/lib/core/expand.js.map +1 -0
- package/dist/lib/core/expr.d.ts +29 -0
- package/dist/lib/core/expr.d.ts.map +1 -0
- package/dist/lib/core/expr.js +313 -0
- package/dist/lib/core/expr.js.map +1 -0
- package/dist/lib/core/format.d.ts +30 -0
- package/dist/lib/core/format.d.ts.map +1 -0
- package/dist/lib/core/format.js +106 -0
- package/dist/lib/core/format.js.map +1 -0
- package/dist/lib/core/lexer.d.ts +54 -0
- package/dist/lib/core/lexer.d.ts.map +1 -0
- package/dist/lib/core/lexer.js +311 -0
- package/dist/lib/core/lexer.js.map +1 -0
- package/dist/lib/core/parser.d.ts +29 -0
- package/dist/lib/core/parser.d.ts.map +1 -0
- package/dist/lib/core/parser.js +674 -0
- package/dist/lib/core/parser.js.map +1 -0
- package/dist/lib/core/resolver.d.ts +37 -0
- package/dist/lib/core/resolver.d.ts.map +1 -0
- package/dist/lib/core/resolver.js +240 -0
- package/dist/lib/core/resolver.js.map +1 -0
- package/dist/lib/core/spec.d.ts +87 -0
- package/dist/lib/core/spec.d.ts.map +1 -0
- package/dist/lib/core/spec.js +207 -0
- package/dist/lib/core/spec.js.map +1 -0
- package/dist/lib/core/state.d.ts +19 -0
- package/dist/lib/core/state.d.ts.map +1 -0
- package/dist/lib/core/state.js +64 -0
- package/dist/lib/core/state.js.map +1 -0
- package/dist/lib/core/tokens.d.ts +36 -0
- package/dist/lib/core/tokens.d.ts.map +1 -0
- package/dist/lib/core/tokens.js +198 -0
- package/dist/lib/core/tokens.js.map +1 -0
- package/dist/lib/export/pages.d.ts +39 -0
- package/dist/lib/export/pages.d.ts.map +1 -0
- package/dist/lib/export/pages.js +95 -0
- package/dist/lib/export/pages.js.map +1 -0
- package/dist/lib/export/raster.d.ts +39 -0
- package/dist/lib/export/raster.d.ts.map +1 -0
- package/dist/lib/export/raster.js +152 -0
- package/dist/lib/export/raster.js.map +1 -0
- package/dist/lib/index.d.ts +33 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +30 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/layout/engine.d.ts +32 -0
- package/dist/lib/layout/engine.d.ts.map +1 -0
- package/dist/lib/layout/engine.js +1063 -0
- package/dist/lib/layout/engine.js.map +1 -0
- package/dist/lib/layout/measure.d.ts +30 -0
- package/dist/lib/layout/measure.d.ts.map +1 -0
- package/dist/lib/layout/measure.js +148 -0
- package/dist/lib/layout/measure.js.map +1 -0
- package/dist/lib/layout/types.d.ts +94 -0
- package/dist/lib/layout/types.d.ts.map +1 -0
- package/dist/lib/layout/types.js +16 -0
- package/dist/lib/layout/types.js.map +1 -0
- package/dist/lib/lsp/server.d.ts +76 -0
- package/dist/lib/lsp/server.d.ts.map +1 -0
- package/dist/lib/lsp/server.js +264 -0
- package/dist/lib/lsp/server.js.map +1 -0
- package/dist/lib/output/docs.d.ts +26 -0
- package/dist/lib/output/docs.d.ts.map +1 -0
- package/dist/lib/output/docs.js +231 -0
- package/dist/lib/output/docs.js.map +1 -0
- package/dist/lib/output/ir.d.ts +105 -0
- package/dist/lib/output/ir.d.ts.map +1 -0
- package/dist/lib/output/ir.js +89 -0
- package/dist/lib/output/ir.js.map +1 -0
- package/dist/lib/output/schema.d.ts +69 -0
- package/dist/lib/output/schema.d.ts.map +1 -0
- package/dist/lib/output/schema.js +84 -0
- package/dist/lib/output/schema.js.map +1 -0
- package/dist/lib/paths.d.ts +12 -0
- package/dist/lib/paths.d.ts.map +1 -0
- package/dist/lib/paths.js +27 -0
- package/dist/lib/paths.js.map +1 -0
- package/dist/lib/playground/examples.d.ts +16 -0
- package/dist/lib/playground/examples.d.ts.map +1 -0
- package/dist/lib/playground/examples.js +515 -0
- package/dist/lib/playground/examples.js.map +1 -0
- package/dist/lib/playground/index.d.ts +51 -0
- package/dist/lib/playground/index.d.ts.map +1 -0
- package/dist/lib/playground/index.js +598 -0
- package/dist/lib/playground/index.js.map +1 -0
- package/dist/lib/render/assets.d.ts +35 -0
- package/dist/lib/render/assets.d.ts.map +1 -0
- package/dist/lib/render/assets.js +114 -0
- package/dist/lib/render/assets.js.map +1 -0
- package/dist/lib/render/backends.d.ts +31 -0
- package/dist/lib/render/backends.d.ts.map +1 -0
- package/dist/lib/render/backends.js +57 -0
- package/dist/lib/render/backends.js.map +1 -0
- package/dist/lib/render/css.d.ts +24 -0
- package/dist/lib/render/css.d.ts.map +1 -0
- package/dist/lib/render/css.js +148 -0
- package/dist/lib/render/css.js.map +1 -0
- package/dist/lib/render/document-html.d.ts +28 -0
- package/dist/lib/render/document-html.d.ts.map +1 -0
- package/dist/lib/render/document-html.js +214 -0
- package/dist/lib/render/document-html.js.map +1 -0
- package/dist/lib/render/dom.d.ts +32 -0
- package/dist/lib/render/dom.d.ts.map +1 -0
- package/dist/lib/render/dom.js +531 -0
- package/dist/lib/render/dom.js.map +1 -0
- package/dist/lib/render/primitives.d.ts +81 -0
- package/dist/lib/render/primitives.d.ts.map +1 -0
- package/dist/lib/render/primitives.js +172 -0
- package/dist/lib/render/primitives.js.map +1 -0
- package/dist/lib/render/react.d.ts +23 -0
- package/dist/lib/render/react.d.ts.map +1 -0
- package/dist/lib/render/react.js +447 -0
- package/dist/lib/render/react.js.map +1 -0
- package/dist/lib/render/svg.d.ts +45 -0
- package/dist/lib/render/svg.d.ts.map +1 -0
- package/dist/lib/render/svg.js +179 -0
- package/dist/lib/render/svg.js.map +1 -0
- package/dist/lib/runtime/proto.d.ts +19 -0
- package/dist/lib/runtime/proto.d.ts.map +1 -0
- package/dist/lib/runtime/proto.js +81 -0
- package/dist/lib/runtime/proto.js.map +1 -0
- package/dist/lib/skill/install.d.ts +28 -0
- package/dist/lib/skill/install.d.ts.map +1 -0
- package/dist/lib/skill/install.js +89 -0
- package/dist/lib/skill/install.js.map +1 -0
- package/dist/lib/workbench/app.d.ts +24 -0
- package/dist/lib/workbench/app.d.ts.map +1 -0
- package/dist/lib/workbench/app.js +45 -0
- package/dist/lib/workbench/app.js.map +1 -0
- package/dist/lib/workbench/assets.d.ts +21 -0
- package/dist/lib/workbench/assets.d.ts.map +1 -0
- package/dist/lib/workbench/assets.js +44 -0
- package/dist/lib/workbench/assets.js.map +1 -0
- package/dist/lib/workbench/client.d.ts +18 -0
- package/dist/lib/workbench/client.d.ts.map +1 -0
- package/dist/lib/workbench/client.js +736 -0
- package/dist/lib/workbench/client.js.map +1 -0
- package/dist/lib/workbench/drag.d.ts +90 -0
- package/dist/lib/workbench/drag.d.ts.map +1 -0
- package/dist/lib/workbench/drag.js +109 -0
- package/dist/lib/workbench/drag.js.map +1 -0
- package/dist/lib/workbench/geometry.d.ts +28 -0
- package/dist/lib/workbench/geometry.d.ts.map +1 -0
- package/dist/lib/workbench/geometry.js +28 -0
- package/dist/lib/workbench/geometry.js.map +1 -0
- package/dist/lib/workbench/select.d.ts +56 -0
- package/dist/lib/workbench/select.d.ts.map +1 -0
- package/dist/lib/workbench/select.js +111 -0
- package/dist/lib/workbench/select.js.map +1 -0
- package/dist/lib/workbench/server.d.ts +223 -0
- package/dist/lib/workbench/server.d.ts.map +1 -0
- package/dist/lib/workbench/server.js +576 -0
- package/dist/lib/workbench/server.js.map +1 -0
- package/dist/lib/workbench/source.d.ts +124 -0
- package/dist/lib/workbench/source.d.ts.map +1 -0
- package/dist/lib/workbench/source.js +405 -0
- package/dist/lib/workbench/source.js.map +1 -0
- package/docs/README.md +49 -0
- package/docs/cheatsheet.md +243 -0
- package/docs/cli.md +95 -0
- package/docs/data.md +112 -0
- package/docs/export.md +106 -0
- package/docs/getting-started.md +105 -0
- package/docs/language.md +136 -0
- package/docs/layout.md +159 -0
- package/docs/plugins.md +82 -0
- package/docs/reference.md +1156 -0
- package/docs/roadmap.md +54 -0
- package/docs/syntax.md +312 -0
- package/docs/workbench.md +125 -0
- package/examples/app.dm +76 -0
- package/examples/assets/avatar.png +0 -0
- package/examples/assets/cover.png +0 -0
- package/examples/assets/logo.svg +4 -0
- package/examples/assets.dm +49 -0
- package/examples/dashboard.dm +64 -0
- package/examples/data.dm +107 -0
- package/examples/layout.dm +93 -0
- package/examples/login.dm +43 -0
- package/examples/login.html +61 -0
- package/examples/plugins/rating/README.md +67 -0
- package/examples/plugins/rating/example.dm +29 -0
- package/examples/plugins/rating/index.ts +122 -0
- package/examples/plugins/rating/package.json +22 -0
- package/examples/recipe/assets/broccoli.jpg +0 -0
- package/examples/recipe/assets/cheesecake.jpg +0 -0
- package/examples/recipe/assets/chicken-pot.jpg +0 -0
- package/examples/recipe/assets/noodles.jpg +0 -0
- package/examples/recipe/assets/shrimp.jpg +0 -0
- package/examples/recipe/assets/tomato-beef.jpg +0 -0
- package/examples/recipe/detail.dm +105 -0
- package/examples/recipe/discover.dm +116 -0
- package/examples/recipe/favorites.dm +115 -0
- package/examples/recipe/index.dm +124 -0
- package/examples/recipe/profile.dm +134 -0
- package/examples/recipe/steps.dm +89 -0
- package/examples/settings.dm +108 -0
- package/package.json +84 -4
- package/skills/designmockdown/REFERENCE.md +373 -0
- package/skills/designmockdown/SKILL.md +179 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Line-level source editor for the workbench.
|
|
3
|
+
*
|
|
4
|
+
* The AST carries only `{line, col}` and attributes carry no position at all, so character-level
|
|
5
|
+
* splicing is not available. That turns out to be an advantage: replacing whole lines cannot damage
|
|
6
|
+
* the comments, blank lines or indentation of any other line, which is exactly the property a
|
|
7
|
+
* "edit the design on the canvas" feature needs - the user's hand-written formatting must survive.
|
|
8
|
+
*
|
|
9
|
+
* The cost is that everything inside one line has to be re-parsed as text. The comma rule for
|
|
10
|
+
* splitting attributes is shared with the lexer (see `splitAttrs`) so the two can never disagree.
|
|
11
|
+
*/
|
|
12
|
+
import type { AttrValue } from '../core/ast.ts';
|
|
13
|
+
/** One line replacement. Line numbers are 1-based. */
|
|
14
|
+
export interface LineEdit {
|
|
15
|
+
line: number;
|
|
16
|
+
text: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Apply a set of line replacements. `edits` must be sorted by line and free of duplicates.
|
|
20
|
+
* Every other line is preserved byte for byte.
|
|
21
|
+
*/
|
|
22
|
+
export declare function applyLineEdits(source: string, edits: LineEdit[]): string;
|
|
23
|
+
/** Insert lines after `after` (0 = at the top). `indent` spaces are prepended to each. */
|
|
24
|
+
export declare function insertLines(source: string, after: number, lines: string[], indent?: number): string;
|
|
25
|
+
/** Delete the inclusive line range [from, to] */
|
|
26
|
+
export declare function deleteLines(source: string, from: number, to: number): string;
|
|
27
|
+
/**
|
|
28
|
+
* Move the line range [from, end] so that it ends up at position `to`.
|
|
29
|
+
*
|
|
30
|
+
* `end` defaults to `from`, so a leaf is a range of one. Containers and tables pass their subtree
|
|
31
|
+
* end: moving only the opening line of a `@table` would drag the header away and leave the rows
|
|
32
|
+
* behind, which parses fine and silently mangles the design.
|
|
33
|
+
*
|
|
34
|
+
* `to` is a line number in the *original* source. After the block is cut out the insert index
|
|
35
|
+
* differs by direction: moving down, the destination line has itself shifted up by the block
|
|
36
|
+
* length; moving up, nothing above it moved. Both collapse to `to - 1` for a single line.
|
|
37
|
+
*/
|
|
38
|
+
export declare function moveLine(source: string, from: number, to: number, end?: number): string;
|
|
39
|
+
/**
|
|
40
|
+
* Turn a source range into a `@define` template and leave a usage in its place.
|
|
41
|
+
*
|
|
42
|
+
* The range is replaced by `@<name>` at the same indentation, and the block moves above the first
|
|
43
|
+
* `@page` at document level - a template has to live outside pages, otherwise the parser scopes it
|
|
44
|
+
* to that one page and the component is not reusable across the document.
|
|
45
|
+
*
|
|
46
|
+
* The block is dedented before it is re-indented under `@define`: the moved lines carry the
|
|
47
|
+
* indentation of their old home, and keeping it would shift the whole template right by one level
|
|
48
|
+
* for every nesting level the selection sat at.
|
|
49
|
+
*/
|
|
50
|
+
export declare function extractDefine(source: string, from: number, to: number, name: string): string;
|
|
51
|
+
export interface AttrBlock {
|
|
52
|
+
/** Index of the opening brace */
|
|
53
|
+
start: number;
|
|
54
|
+
/** Index just past the closing brace */
|
|
55
|
+
end: number;
|
|
56
|
+
/** The text between the braces */
|
|
57
|
+
inner: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Find the attribute block on a component line.
|
|
61
|
+
*
|
|
62
|
+
* The block may come before or after the content (`@button {primary} 提交` and `@button 提交 {primary}`
|
|
63
|
+
* are both legal), so this scans for the first brace group that parses as attributes rather than
|
|
64
|
+
* assuming a position. A `{...}` group that fails to parse is a data reference and is skipped.
|
|
65
|
+
*/
|
|
66
|
+
export declare function findAttrBlock(line: string): AttrBlock | null;
|
|
67
|
+
/** One attribute together with the character range it occupies inside the line */
|
|
68
|
+
export interface AttrSpan {
|
|
69
|
+
key: string;
|
|
70
|
+
value: AttrValue;
|
|
71
|
+
/** Character range in the line, covering `key=value` or the bare flag */
|
|
72
|
+
start: number;
|
|
73
|
+
end: number;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Parse the attributes of a component line, with their character ranges.
|
|
77
|
+
*
|
|
78
|
+
* The ranges are what makes surgical editing possible: changing one attribute rewrites only its own
|
|
79
|
+
* span and leaves the rest of the line - including the user's spacing - untouched.
|
|
80
|
+
*/
|
|
81
|
+
export declare function parseAttrSpans(line: string): AttrSpan[];
|
|
82
|
+
/** Read one attribute off a component line; undefined when absent */
|
|
83
|
+
export declare function getAttrOnLine(line: string, key: string): AttrValue | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Set one attribute on a component line, preserving everything else on it.
|
|
86
|
+
*
|
|
87
|
+
* setAttrOnLine('@button 提交 {primary, size=sm}', 'bg', 'brand')
|
|
88
|
+
* → '@button 提交 {primary, size=sm, bg=brand}'
|
|
89
|
+
* setAttrOnLine('@button 提交', 'bg', 'brand')
|
|
90
|
+
* → '@button 提交 {bg=brand}'
|
|
91
|
+
* setAttrOnLine('@box {p=16}', 'p', 24)
|
|
92
|
+
* → '@box {p=24}'
|
|
93
|
+
*/
|
|
94
|
+
export declare function setAttrOnLine(line: string, key: string, value: AttrValue): string;
|
|
95
|
+
/** Remove an attribute from a component line. Absent keys leave the line untouched. */
|
|
96
|
+
export declare function removeAttrOnLine(line: string, key: string): string;
|
|
97
|
+
/**
|
|
98
|
+
* Set the inline content of a component line (the text between `@name` and the attribute block).
|
|
99
|
+
*
|
|
100
|
+
* setContentOnLine('@button 提交 {primary}', '立即购买') → '@button 立即购买 {primary}'
|
|
101
|
+
*
|
|
102
|
+
* A `#id` belongs to the node, not the content, so it is carried over rather than overwritten, and
|
|
103
|
+
* it stays on the side of the content where the user put it.
|
|
104
|
+
*/
|
|
105
|
+
export declare function setContentOnLine(line: string, content: string): string;
|
|
106
|
+
/** The component name on a line, or null when the line is not a component */
|
|
107
|
+
export declare function componentNameOnLine(line: string): string | null;
|
|
108
|
+
/**
|
|
109
|
+
* The name a line carries, from either spelling: `@table #sales` or `@table {id=sales}`.
|
|
110
|
+
*
|
|
111
|
+
* Both exist because the shorthand is only read when something follows it (the lexer treats a
|
|
112
|
+
* lone `#token` as content), and components that draw no text - a table - have nothing to follow.
|
|
113
|
+
*/
|
|
114
|
+
export declare function idOnLine(line: string): string | null;
|
|
115
|
+
/**
|
|
116
|
+
* Give a component line a name without disturbing anything else.
|
|
117
|
+
*
|
|
118
|
+
* Writes the attribute form: it works for every component, including ones whose content is
|
|
119
|
+
* ignored, and it cannot be mistaken for text.
|
|
120
|
+
*/
|
|
121
|
+
export declare function setIdOnLine(line: string, id: string): string;
|
|
122
|
+
/** The inline content of a component line (text outside the attribute block, minus any #id) */
|
|
123
|
+
export declare function contentOnLine(line: string): string;
|
|
124
|
+
//# sourceMappingURL=source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../../../src/workbench/source.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAG/C,sDAAsD;AACtD,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;CACb;AAsBD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,MAAM,CAMxE;AAED,0FAA0F;AAC1F,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,MAAM,SAAI,GAAG,MAAM,CAS9F;AAED,iDAAiD;AACjD,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAO5E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,SAAO,GAAG,MAAM,CAarF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,E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,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAG5D;AAED,+FAA+F;AAC/F,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAOlD"}
|
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Line-level source editor for the workbench.
|
|
3
|
+
*
|
|
4
|
+
* The AST carries only `{line, col}` and attributes carry no position at all, so character-level
|
|
5
|
+
* splicing is not available. That turns out to be an advantage: replacing whole lines cannot damage
|
|
6
|
+
* the comments, blank lines or indentation of any other line, which is exactly the property a
|
|
7
|
+
* "edit the design on the canvas" feature needs - the user's hand-written formatting must survive.
|
|
8
|
+
*
|
|
9
|
+
* The cost is that everything inside one line has to be re-parsed as text. The comma rule for
|
|
10
|
+
* splitting attributes is shared with the lexer (see `splitAttrs`) so the two can never disagree.
|
|
11
|
+
*/
|
|
12
|
+
import { coerce, splitAttrs } from "../core/lexer.js";
|
|
13
|
+
/** Split source into lines, remembering whether it ended with a newline */
|
|
14
|
+
function splitLines(source) {
|
|
15
|
+
const trailingNewline = source.endsWith('\n') || source.endsWith('\r');
|
|
16
|
+
const lines = source.split(/\r?\n/);
|
|
17
|
+
// A trailing newline produces a final empty element that is not a real line
|
|
18
|
+
if (trailingNewline && lines.length > 0 && lines[lines.length - 1] === '')
|
|
19
|
+
lines.pop();
|
|
20
|
+
return { lines, trailingNewline };
|
|
21
|
+
}
|
|
22
|
+
function joinLines(lines, trailingNewline) {
|
|
23
|
+
return lines.join('\n') + (trailingNewline ? '\n' : '');
|
|
24
|
+
}
|
|
25
|
+
/** Guard: a line number must address a real line */
|
|
26
|
+
function checkLine(lines, line, what) {
|
|
27
|
+
if (!Number.isInteger(line) || line < 1 || line > lines.length) {
|
|
28
|
+
throw new RangeError(`${what}: line ${line} is out of range (1..${lines.length})`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Apply a set of line replacements. `edits` must be sorted by line and free of duplicates.
|
|
33
|
+
* Every other line is preserved byte for byte.
|
|
34
|
+
*/
|
|
35
|
+
export function applyLineEdits(source, edits) {
|
|
36
|
+
if (edits.length === 0)
|
|
37
|
+
return source;
|
|
38
|
+
const { lines, trailingNewline } = splitLines(source);
|
|
39
|
+
for (const e of edits)
|
|
40
|
+
checkLine(lines, e.line, 'applyLineEdits');
|
|
41
|
+
for (const e of edits)
|
|
42
|
+
lines[e.line - 1] = e.text;
|
|
43
|
+
return joinLines(lines, trailingNewline);
|
|
44
|
+
}
|
|
45
|
+
/** Insert lines after `after` (0 = at the top). `indent` spaces are prepended to each. */
|
|
46
|
+
export function insertLines(source, after, lines, indent = 0) {
|
|
47
|
+
const { lines: all, trailingNewline } = splitLines(source);
|
|
48
|
+
if (after < 0 || after > all.length) {
|
|
49
|
+
throw new RangeError(`insertLines: after ${after} is out of range (0..${all.length})`);
|
|
50
|
+
}
|
|
51
|
+
const pad = ' '.repeat(Math.max(0, indent));
|
|
52
|
+
const inserted = lines.map((l) => pad + l);
|
|
53
|
+
all.splice(after, 0, ...inserted);
|
|
54
|
+
return joinLines(all, trailingNewline);
|
|
55
|
+
}
|
|
56
|
+
/** Delete the inclusive line range [from, to] */
|
|
57
|
+
export function deleteLines(source, from, to) {
|
|
58
|
+
const { lines, trailingNewline } = splitLines(source);
|
|
59
|
+
checkLine(lines, from, 'deleteLines');
|
|
60
|
+
checkLine(lines, to, 'deleteLines');
|
|
61
|
+
if (to < from)
|
|
62
|
+
throw new RangeError(`deleteLines: to ${to} is before from ${from}`);
|
|
63
|
+
lines.splice(from - 1, to - from + 1);
|
|
64
|
+
return joinLines(lines, trailingNewline);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Move the line range [from, end] so that it ends up at position `to`.
|
|
68
|
+
*
|
|
69
|
+
* `end` defaults to `from`, so a leaf is a range of one. Containers and tables pass their subtree
|
|
70
|
+
* end: moving only the opening line of a `@table` would drag the header away and leave the rows
|
|
71
|
+
* behind, which parses fine and silently mangles the design.
|
|
72
|
+
*
|
|
73
|
+
* `to` is a line number in the *original* source. After the block is cut out the insert index
|
|
74
|
+
* differs by direction: moving down, the destination line has itself shifted up by the block
|
|
75
|
+
* length; moving up, nothing above it moved. Both collapse to `to - 1` for a single line.
|
|
76
|
+
*/
|
|
77
|
+
export function moveLine(source, from, to, end = from) {
|
|
78
|
+
const { lines, trailingNewline } = splitLines(source);
|
|
79
|
+
checkLine(lines, from, 'moveLine');
|
|
80
|
+
checkLine(lines, to, 'moveLine');
|
|
81
|
+
checkLine(lines, end, 'moveLine');
|
|
82
|
+
if (end < from)
|
|
83
|
+
throw new RangeError(`moveLine: end ${end} is before from ${from}`);
|
|
84
|
+
if (to === from)
|
|
85
|
+
return source;
|
|
86
|
+
// A destination inside the block means "stay where you are"
|
|
87
|
+
if (to > from && to <= end)
|
|
88
|
+
return source;
|
|
89
|
+
const length = end - from + 1;
|
|
90
|
+
const block = lines.splice(from - 1, length);
|
|
91
|
+
lines.splice(to < from ? to - 1 : to - length, 0, ...block);
|
|
92
|
+
return joinLines(lines, trailingNewline);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Turn a source range into a `@define` template and leave a usage in its place.
|
|
96
|
+
*
|
|
97
|
+
* The range is replaced by `@<name>` at the same indentation, and the block moves above the first
|
|
98
|
+
* `@page` at document level - a template has to live outside pages, otherwise the parser scopes it
|
|
99
|
+
* to that one page and the component is not reusable across the document.
|
|
100
|
+
*
|
|
101
|
+
* The block is dedented before it is re-indented under `@define`: the moved lines carry the
|
|
102
|
+
* indentation of their old home, and keeping it would shift the whole template right by one level
|
|
103
|
+
* for every nesting level the selection sat at.
|
|
104
|
+
*/
|
|
105
|
+
export function extractDefine(source, from, to, name) {
|
|
106
|
+
const { lines, trailingNewline } = splitLines(source);
|
|
107
|
+
checkLine(lines, from, 'extractDefine');
|
|
108
|
+
checkLine(lines, to, 'extractDefine');
|
|
109
|
+
if (to < from)
|
|
110
|
+
throw new RangeError(`extractDefine: to ${to} is before from ${from}`);
|
|
111
|
+
// Checked here rather than left to the parser: a bad name produces a file that no longer
|
|
112
|
+
// parses, and the failure would only surface on the next keystroke as a whole broken document
|
|
113
|
+
if (!/^[a-z][a-z0-9-]*$/.test(name)) {
|
|
114
|
+
throw new RangeError(`extractDefine: "${name}" is not a valid component name (a-z, 0-9, hyphen)`);
|
|
115
|
+
}
|
|
116
|
+
const block = lines.slice(from - 1, to);
|
|
117
|
+
const indent = (block[0].match(/^[ \t]*/) ?? [''])[0].length;
|
|
118
|
+
const body = block.map((l) => (l.trim() === '' ? '' : l.slice(indent)));
|
|
119
|
+
const usage = ' '.repeat(indent) + '@' + name;
|
|
120
|
+
// Locate the first @page before touching the array, so the indices below refer to one snapshot
|
|
121
|
+
let at = lines.findIndex((l) => l.startsWith('@page '));
|
|
122
|
+
if (at < 0)
|
|
123
|
+
at = lines.length;
|
|
124
|
+
lines.splice(from - 1, to - from + 1, usage);
|
|
125
|
+
// Every line removed from above the insertion point moves it up by one
|
|
126
|
+
const removedAbove = Math.max(0, Math.min(to, at) - from + 1);
|
|
127
|
+
const defineLines = ['@define ' + name, ...body.map((l) => (l === '' ? '' : ' ' + l)), ''];
|
|
128
|
+
lines.splice(at - removedAbove, 0, ...defineLines);
|
|
129
|
+
return joinLines(lines, trailingNewline);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Find the attribute block on a component line.
|
|
133
|
+
*
|
|
134
|
+
* The block may come before or after the content (`@button {primary} 提交` and `@button 提交 {primary}`
|
|
135
|
+
* are both legal), so this scans for the first brace group that parses as attributes rather than
|
|
136
|
+
* assuming a position. A `{...}` group that fails to parse is a data reference and is skipped.
|
|
137
|
+
*/
|
|
138
|
+
export function findAttrBlock(line) {
|
|
139
|
+
let i = 0;
|
|
140
|
+
while (i < line.length) {
|
|
141
|
+
const open = line.indexOf('{', i);
|
|
142
|
+
if (open < 0)
|
|
143
|
+
return null;
|
|
144
|
+
const close = matchingBrace(line, open);
|
|
145
|
+
if (close < 0)
|
|
146
|
+
return null;
|
|
147
|
+
const inner = line.slice(open + 1, close);
|
|
148
|
+
if (parsesAsAttrs(inner))
|
|
149
|
+
return { start: open, end: close + 1, inner };
|
|
150
|
+
i = open + 1;
|
|
151
|
+
}
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
/** Does this text parse as an attribute block? (A data reference does not.) */
|
|
155
|
+
function parsesAsAttrs(inner) {
|
|
156
|
+
if (inner.trim() === '')
|
|
157
|
+
return true;
|
|
158
|
+
for (const part of splitAttrs(inner)) {
|
|
159
|
+
const p = part.trim();
|
|
160
|
+
if (p === '')
|
|
161
|
+
continue;
|
|
162
|
+
const eq = p.indexOf('=');
|
|
163
|
+
if (eq < 0) {
|
|
164
|
+
if (!/^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(p))
|
|
165
|
+
return false;
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
if (!/^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(p.slice(0, eq).trim()))
|
|
169
|
+
return false;
|
|
170
|
+
if (p.slice(eq + 1).trim() === '')
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
/** Index of the brace matching the one at `start`, or -1. Quotes protect their contents. */
|
|
176
|
+
function matchingBrace(s, start) {
|
|
177
|
+
let depth = 0;
|
|
178
|
+
let quote = null;
|
|
179
|
+
for (let i = start; i < s.length; i++) {
|
|
180
|
+
const c = s[i];
|
|
181
|
+
if (quote) {
|
|
182
|
+
if (c === quote)
|
|
183
|
+
quote = null;
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
if (c === '"' || c === "'") {
|
|
187
|
+
quote = c;
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
if (c === '{')
|
|
191
|
+
depth++;
|
|
192
|
+
else if (c === '}') {
|
|
193
|
+
depth--;
|
|
194
|
+
if (depth === 0)
|
|
195
|
+
return i;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return -1;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Parse the attributes of a component line, with their character ranges.
|
|
202
|
+
*
|
|
203
|
+
* The ranges are what makes surgical editing possible: changing one attribute rewrites only its own
|
|
204
|
+
* span and leaves the rest of the line - including the user's spacing - untouched.
|
|
205
|
+
*/
|
|
206
|
+
export function parseAttrSpans(line) {
|
|
207
|
+
const block = findAttrBlock(line);
|
|
208
|
+
if (!block)
|
|
209
|
+
return [];
|
|
210
|
+
const out = [];
|
|
211
|
+
let cursor = block.start + 1;
|
|
212
|
+
for (const part of splitAttrs(block.inner)) {
|
|
213
|
+
// Locate this part inside the block so the span refers to the real line
|
|
214
|
+
const at = block.inner.indexOf(part, cursor - (block.start + 1));
|
|
215
|
+
const offset = at < 0 ? cursor : block.start + 1 + at;
|
|
216
|
+
const eq = part.indexOf('=');
|
|
217
|
+
const key = (eq < 0 ? part : part.slice(0, eq)).trim();
|
|
218
|
+
if (key === '') {
|
|
219
|
+
cursor = offset + part.length;
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
out.push({
|
|
223
|
+
key,
|
|
224
|
+
value: eq < 0 ? true : coerce(part.slice(eq + 1).trim()),
|
|
225
|
+
start: offset,
|
|
226
|
+
end: offset + part.length,
|
|
227
|
+
});
|
|
228
|
+
cursor = offset + part.length;
|
|
229
|
+
}
|
|
230
|
+
return out;
|
|
231
|
+
}
|
|
232
|
+
/** Read one attribute off a component line; undefined when absent */
|
|
233
|
+
export function getAttrOnLine(line, key) {
|
|
234
|
+
const found = parseAttrSpans(line).find((a) => a.key === key);
|
|
235
|
+
return found?.value;
|
|
236
|
+
}
|
|
237
|
+
/** Render a value the way it must appear in source */
|
|
238
|
+
function renderValue(value) {
|
|
239
|
+
if (value === true)
|
|
240
|
+
return '';
|
|
241
|
+
if (value === false)
|
|
242
|
+
return 'false';
|
|
243
|
+
if (typeof value === 'number')
|
|
244
|
+
return String(value);
|
|
245
|
+
// Quote when the value would otherwise be ambiguous: spaces, commas, braces or quotes
|
|
246
|
+
if (/[\s,{}"'=]/.test(value))
|
|
247
|
+
return `"${value.replace(/"/g, '\\"')}"`;
|
|
248
|
+
return value;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* The character range to cut when dropping an attribute: the span itself plus the separator on
|
|
252
|
+
* either side, so no dangling comma or double space is left behind.
|
|
253
|
+
*/
|
|
254
|
+
function dropRange(line, span) {
|
|
255
|
+
let start = span.start;
|
|
256
|
+
while (start > 0 && /[\s,]/.test(line[start - 1]))
|
|
257
|
+
start--;
|
|
258
|
+
let end = span.end;
|
|
259
|
+
while (end < line.length && /[\s,]/.test(line[end]))
|
|
260
|
+
end++;
|
|
261
|
+
return [start, end];
|
|
262
|
+
}
|
|
263
|
+
/** Cut the given ranges out of a line */
|
|
264
|
+
function cutRanges(line, ranges) {
|
|
265
|
+
const sorted = [...ranges].sort((a, b) => a[0] - b[0]);
|
|
266
|
+
let out = '';
|
|
267
|
+
let cursor = 0;
|
|
268
|
+
for (const [start, end] of sorted) {
|
|
269
|
+
if (start < cursor)
|
|
270
|
+
continue;
|
|
271
|
+
out += line.slice(cursor, start);
|
|
272
|
+
cursor = end;
|
|
273
|
+
}
|
|
274
|
+
return out + line.slice(cursor);
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Set one attribute on a component line, preserving everything else on it.
|
|
278
|
+
*
|
|
279
|
+
* setAttrOnLine('@button 提交 {primary, size=sm}', 'bg', 'brand')
|
|
280
|
+
* → '@button 提交 {primary, size=sm, bg=brand}'
|
|
281
|
+
* setAttrOnLine('@button 提交', 'bg', 'brand')
|
|
282
|
+
* → '@button 提交 {bg=brand}'
|
|
283
|
+
* setAttrOnLine('@box {p=16}', 'p', 24)
|
|
284
|
+
* → '@box {p=24}'
|
|
285
|
+
*/
|
|
286
|
+
export function setAttrOnLine(line, key, value) {
|
|
287
|
+
const rendered = renderValue(value);
|
|
288
|
+
const replacement = rendered === '' ? key : `${key}=${rendered}`;
|
|
289
|
+
const spans = parseAttrSpans(line).filter((s) => s.key === key);
|
|
290
|
+
if (spans.length > 0) {
|
|
291
|
+
// Collapse duplicates first, so exactly one occurrence is left to replace. `{p=16, p=24}` is
|
|
292
|
+
// legal input but writing it back would be confusing.
|
|
293
|
+
let work = line;
|
|
294
|
+
if (spans.length > 1)
|
|
295
|
+
work = cutRanges(line, spans.slice(1).map((s) => dropRange(line, s)));
|
|
296
|
+
const target = parseAttrSpans(work).find((s) => s.key === key);
|
|
297
|
+
return work.slice(0, target.start) + replacement + work.slice(target.end);
|
|
298
|
+
}
|
|
299
|
+
const block = findAttrBlock(line);
|
|
300
|
+
if (block) {
|
|
301
|
+
const inner = block.inner.trim();
|
|
302
|
+
const sep = inner === '' ? '' : ', ';
|
|
303
|
+
return line.slice(0, block.start + 1) + inner + sep + replacement + line.slice(block.end - 1);
|
|
304
|
+
}
|
|
305
|
+
// No block yet: append one, keeping any trailing comment at the end of the line
|
|
306
|
+
const commentAt = line.indexOf('//');
|
|
307
|
+
const body = commentAt < 0 ? line : line.slice(0, commentAt);
|
|
308
|
+
const comment = commentAt < 0 ? '' : line.slice(commentAt);
|
|
309
|
+
return `${body.replace(/\s+$/, '')} {${replacement}}${comment === '' ? '' : ' ' + comment}`;
|
|
310
|
+
}
|
|
311
|
+
/** Remove an attribute from a component line. Absent keys leave the line untouched. */
|
|
312
|
+
export function removeAttrOnLine(line, key) {
|
|
313
|
+
const spans = parseAttrSpans(line).filter((s) => s.key === key);
|
|
314
|
+
if (spans.length === 0)
|
|
315
|
+
return line;
|
|
316
|
+
const out = cutRanges(line, spans.map((s) => dropRange(line, s)));
|
|
317
|
+
// An emptied block is noise; drop it entirely
|
|
318
|
+
const block = findAttrBlock(out);
|
|
319
|
+
if (block && block.inner.trim() === '') {
|
|
320
|
+
return out.slice(0, block.start).replace(/\s+$/, '') + out.slice(block.end);
|
|
321
|
+
}
|
|
322
|
+
return out;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* The `#id` rule, copied from the lexer's `extractId`: the first `#token` that is followed by
|
|
326
|
+
* whitespace, the end of the line, or a brace. Sharing the rule matters because the id may sit
|
|
327
|
+
* before or after the content (`@card #hero 标题` and `@card 标题 #hero` are both legal), and a
|
|
328
|
+
* different rule here would move the user's id around.
|
|
329
|
+
*/
|
|
330
|
+
const ID_RE = /(?:^|\s)#([a-zA-Z_][a-zA-Z0-9_-]*)(?=\s|$|\{)/;
|
|
331
|
+
/** Split the pre-block text into its content and its #id, keeping track of where the id sat */
|
|
332
|
+
function splitContentAndId(before) {
|
|
333
|
+
const m = ID_RE.exec(before);
|
|
334
|
+
if (!m)
|
|
335
|
+
return { content: before.trim(), id: '', idFirst: false };
|
|
336
|
+
const id = `#${m[1]}`;
|
|
337
|
+
const rest = (before.slice(0, m.index) + ' ' + before.slice(m.index + m[0].length)).trim();
|
|
338
|
+
return { content: rest, id, idFirst: before.slice(0, m.index).trim() === '' };
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Set the inline content of a component line (the text between `@name` and the attribute block).
|
|
342
|
+
*
|
|
343
|
+
* setContentOnLine('@button 提交 {primary}', '立即购买') → '@button 立即购买 {primary}'
|
|
344
|
+
*
|
|
345
|
+
* A `#id` belongs to the node, not the content, so it is carried over rather than overwritten, and
|
|
346
|
+
* it stays on the side of the content where the user put it.
|
|
347
|
+
*/
|
|
348
|
+
export function setContentOnLine(line, content) {
|
|
349
|
+
const m = /^(\s*)@([a-zA-Z][a-zA-Z0-9_-]*)(.*)$/s.exec(line);
|
|
350
|
+
if (!m)
|
|
351
|
+
return line;
|
|
352
|
+
const [, indent, name, rest] = m;
|
|
353
|
+
const block = findAttrBlock(rest);
|
|
354
|
+
const before = block ? rest.slice(0, block.start) : rest;
|
|
355
|
+
// The block starts at its opening brace, so slicing from there keeps it intact
|
|
356
|
+
const after = block ? rest.slice(block.start) : '';
|
|
357
|
+
const { id, idFirst } = splitContentAndId(before);
|
|
358
|
+
const newContent = content.trim() === '' ? '' : ` ${content.trim()}`;
|
|
359
|
+
const newId = id === '' ? '' : ` ${id}`;
|
|
360
|
+
const middle = idFirst ? `${newId}${newContent}` : `${newContent}${newId}`;
|
|
361
|
+
// The block is re-attached from its opening brace, so the space that used to separate it from the
|
|
362
|
+
// content has to be put back - including when the content is being cleared
|
|
363
|
+
const gap = after === '' ? '' : ' ';
|
|
364
|
+
return `${indent}@${name}${middle}${gap}${after}`;
|
|
365
|
+
}
|
|
366
|
+
/** The component name on a line, or null when the line is not a component */
|
|
367
|
+
export function componentNameOnLine(line) {
|
|
368
|
+
const m = /^\s*@([a-zA-Z][a-zA-Z0-9_-]*)/.exec(line);
|
|
369
|
+
return m ? m[1] : null;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* The name a line carries, from either spelling: `@table #sales` or `@table {id=sales}`.
|
|
373
|
+
*
|
|
374
|
+
* Both exist because the shorthand is only read when something follows it (the lexer treats a
|
|
375
|
+
* lone `#token` as content), and components that draw no text - a table - have nothing to follow.
|
|
376
|
+
*/
|
|
377
|
+
export function idOnLine(line) {
|
|
378
|
+
const attr = /(?:^|[{,])\s*id\s*=\s*"?([a-zA-Z_][a-zA-Z0-9_-]*)"?/.exec(line);
|
|
379
|
+
if (attr)
|
|
380
|
+
return attr[1];
|
|
381
|
+
const m = ID_RE.exec(line);
|
|
382
|
+
return m ? m[1] : null;
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Give a component line a name without disturbing anything else.
|
|
386
|
+
*
|
|
387
|
+
* Writes the attribute form: it works for every component, including ones whose content is
|
|
388
|
+
* ignored, and it cannot be mistaken for text.
|
|
389
|
+
*/
|
|
390
|
+
export function setIdOnLine(line, id) {
|
|
391
|
+
if (idOnLine(line))
|
|
392
|
+
return line;
|
|
393
|
+
return setAttrOnLine(line, 'id', id);
|
|
394
|
+
}
|
|
395
|
+
/** The inline content of a component line (text outside the attribute block, minus any #id) */
|
|
396
|
+
export function contentOnLine(line) {
|
|
397
|
+
const m = /^(\s*)@([a-zA-Z][a-zA-Z0-9_-]*)(.*)$/s.exec(line);
|
|
398
|
+
if (!m)
|
|
399
|
+
return '';
|
|
400
|
+
const rest = m[3];
|
|
401
|
+
const block = findAttrBlock(rest);
|
|
402
|
+
const before = block ? rest.slice(0, block.start) : rest;
|
|
403
|
+
return splitContentAndId(before).content;
|
|
404
|
+
}
|
|
405
|
+
//# sourceMappingURL=source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source.js","sourceRoot":"","sources":["../../../src/workbench/source.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAQrD,2EAA2E;AAC3E,SAAS,UAAU,CAAC,MAAc;IAChC,MAAM,eAAe,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;IACtE,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IACnC,4EAA4E;IAC5E,IAAI,eAAe,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE;QAAE,KAAK,CAAC,GAAG,EAAE,CAAA;IACtF,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,CAAA;AACnC,CAAC;AAED,SAAS,SAAS,CAAC,KAAe,EAAE,eAAwB;IAC1D,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;AACzD,CAAC;AAED,oDAAoD;AACpD,SAAS,SAAS,CAAC,KAAe,EAAE,IAAY,EAAE,IAAY;IAC5D,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,I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;AACtC,CAAC;AAED,+FAA+F;AAC/F,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,MAAM,CAAC,GAAG,uCAAuC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC5D,IAAI,CAAC,CAAC;QAAE,OAAO,EAAE,CAAA;IACjB,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;IACjB,MAAM,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,CAAA;IACjC,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IACxD,OAAO,iBAAiB,CAAC,MAAM,CAAC,CAAC,OAAO,CAAA;AAC1C,CAAC"}
|
package/docs/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# DesignMockdown 文档
|
|
2
|
+
|
|
3
|
+
按顺序读下去就是一本教程:从「跑起来」到「写出一个多页、可点、能接数据的原型」,
|
|
4
|
+
再到「把它接进自己的工具链」。只想查某个属性或组件时,直接跳 [reference.md](reference.md)。
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 教程
|
|
9
|
+
|
|
10
|
+
| # | 章节 | 你会学到 | 读完能做什么 |
|
|
11
|
+
| --- | --- | --- | --- |
|
|
12
|
+
| 0 | [getting-started.md](getting-started.md) | 装好、第一个页面、五个常用命令、编辑器 | 跑起来并导出第一张图 |
|
|
13
|
+
| 1 | [language.md](language.md) | 行即组件、缩进、属性块、插槽、多页 + `goto:`、`@define` | 写出一个多页可点的原型 |
|
|
14
|
+
| 2 | [layout.md](layout.md) | 默认列 / `@row` / `@grid`、尺寸与间距、绝对定位与 `pin`、令牌主题、图标图片、逃生舱 | 把页面摆成你想要的样子 |
|
|
15
|
+
| 3 | [data.md](data.md) | 页面数据、插值、表达式、`@if` / `@for`、`@state`、`@anim` | 让设计稿接上真实数据与交互态 |
|
|
16
|
+
| 4 | [workbench.md](workbench.md) | 画布编辑、间距标注、连线、预览、协同、playground | 在画布上直接改,并和别人一起评审 |
|
|
17
|
+
| 5 | [export.md](export.md) | 四个后端、批量导出、PNG/PDF、当库用、IR | 交付图、交付代码、接进构建 |
|
|
18
|
+
| 6 | [plugins.md](plugins.md) | 用 TS 注册一个新组件 | 给语言加一种新的绘制能力 |
|
|
19
|
+
|
|
20
|
+
## 参考
|
|
21
|
+
|
|
22
|
+
| 文件 | 内容 | 怎么来的 |
|
|
23
|
+
| --- | --- | --- |
|
|
24
|
+
| [reference.md](reference.md) | 属性、刻度、画布、令牌、组件全表 | **生成**:`npm run docs`(勿手改) |
|
|
25
|
+
| [syntax.md](syntax.md) | 语法规范:规则与语义、错误表、坐标约定 | 手写,规范级别 |
|
|
26
|
+
| [cheatsheet.md](cheatsheet.md) | 一页纸速查 | 手写 |
|
|
27
|
+
| [cli.md](cli.md) | 十二个命令、选项、退出码 | 手写 |
|
|
28
|
+
|
|
29
|
+
## 其他
|
|
30
|
+
|
|
31
|
+
- [roadmap.md](roadmap.md) — 已交付的五层能力,以及几个关键决策的理由
|
|
32
|
+
- [贡献指南](../CONTRIBUTING.md) — 开发、测试、golden、发布
|
|
33
|
+
- 示例源码在 [`examples/`](../examples/),内嵌的九个示例用 `node src/cli.ts playground` 打开
|
|
34
|
+
- 给 agent 的 skill 在 [`skills/designmockdown/`](../skills/designmockdown/)(NearWork 一行装好:`npm run skill:install`)
|
|
35
|
+
- 架构与硬规则在 [AGENTS.md](../AGENTS.md)(给协作者和 agent 看的)
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## 文档怎么维护
|
|
40
|
+
|
|
41
|
+
一句话:**清单归生成,规则归手写**。
|
|
42
|
+
|
|
43
|
+
- 属性说明、刻度、画布、令牌、语法片段、指令写在 `src/core/spec.ts`;
|
|
44
|
+
- `src/output/docs.ts` 把它和组件注册表渲染成 `reference.md`(人读)和 `skills/designmockdown/REFERENCE.md`(LLM 读);
|
|
45
|
+
- CI 跑 `node src/cli.ts docs --check`,过期即失败;
|
|
46
|
+
- `test/docs-links.test.ts` 检查所有相对链接指向真实文件,
|
|
47
|
+
`test/spec.test.ts` 要求每份手写文档都能链到 `reference.md`。
|
|
48
|
+
|
|
49
|
+
所以「文档和实现对不上」这件事,在这里是一个会红的测试,不是一次 review 的运气。
|