@link-foundation/ui-designer 0.0.0-stage → 0.1.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 +24 -0
- package/README.md +180 -2
- package/package.json +41 -4
- package/src/actions.js +195 -0
- package/src/canvas-view.js +171 -0
- package/src/canvas.js +317 -0
- package/src/catalog.js +81 -0
- package/src/commands.js +229 -0
- package/src/designer.css +316 -0
- package/src/designer.js +266 -0
- package/src/designer.lino +104 -0
- package/src/dom.js +22 -0
- package/src/drop.js +82 -0
- package/src/editing.js +124 -0
- package/src/geometry.js +54 -0
- package/src/index.js +28 -0
- package/src/layout-text.js +3 -0
- package/src/panels.js +243 -0
- package/src/selection.js +68 -0
- package/src/snap.js +43 -0
- package/src/source-panel.js +111 -0
- package/src/sync.js +284 -0
- package/src/timeline/commands.js +208 -0
- package/src/timeline/layout-text.js +3 -0
- package/src/timeline/model.js +128 -0
- package/src/timeline/preview.js +105 -0
- package/src/timeline/properties.js +86 -0
- package/src/timeline/scale.js +16 -0
- package/src/timeline/timeline.js +757 -0
- package/src/timeline/timeline.lino +23 -0
package/src/designer.css
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
.ui-designer {
|
|
2
|
+
color-scheme: light dark;
|
|
3
|
+
font:
|
|
4
|
+
14px/1.4 system-ui,
|
|
5
|
+
sans-serif;
|
|
6
|
+
background: Canvas;
|
|
7
|
+
color: CanvasText;
|
|
8
|
+
height: 100vh;
|
|
9
|
+
display: flex;
|
|
10
|
+
flex-direction: column;
|
|
11
|
+
--color-primary: #2457b3;
|
|
12
|
+
--color-on-primary: #fff;
|
|
13
|
+
}
|
|
14
|
+
.ui-designer > ui-document {
|
|
15
|
+
display: flex;
|
|
16
|
+
flex-direction: column;
|
|
17
|
+
flex: 1;
|
|
18
|
+
min-height: 0;
|
|
19
|
+
}
|
|
20
|
+
.ui-designer [data-link-id='toolbar'] {
|
|
21
|
+
flex-wrap: wrap;
|
|
22
|
+
padding: 8px;
|
|
23
|
+
border-bottom: 1px solid GrayText;
|
|
24
|
+
}
|
|
25
|
+
.ui-designer [data-link-id='toolbar'] > ui-button > button {
|
|
26
|
+
padding: 6px 10px;
|
|
27
|
+
}
|
|
28
|
+
.ui-designer [data-link-id='workspace'] {
|
|
29
|
+
flex: 1;
|
|
30
|
+
min-height: 0;
|
|
31
|
+
}
|
|
32
|
+
.ui-designer ui-panel {
|
|
33
|
+
padding: 10px;
|
|
34
|
+
overflow: auto;
|
|
35
|
+
min-height: 0;
|
|
36
|
+
box-sizing: border-box;
|
|
37
|
+
}
|
|
38
|
+
.ui-designer [data-link-id='canvas'] {
|
|
39
|
+
padding: 18px;
|
|
40
|
+
background: color-mix(in srgb, CanvasText 5%, Canvas);
|
|
41
|
+
}
|
|
42
|
+
.designer-canvas {
|
|
43
|
+
min-height: 100%;
|
|
44
|
+
padding: 20px;
|
|
45
|
+
box-sizing: border-box;
|
|
46
|
+
background: Canvas;
|
|
47
|
+
outline-offset: -3px;
|
|
48
|
+
}
|
|
49
|
+
.designer-canvas > ui-document {
|
|
50
|
+
min-height: 230px;
|
|
51
|
+
}
|
|
52
|
+
.ui-designer[data-mode='design'] .designer-canvas {
|
|
53
|
+
touch-action: none;
|
|
54
|
+
user-select: none;
|
|
55
|
+
}
|
|
56
|
+
.designer-canvas [data-selected] {
|
|
57
|
+
outline: 2px dashed #2457b3;
|
|
58
|
+
outline-offset: 2px;
|
|
59
|
+
}
|
|
60
|
+
.designer-toolbox {
|
|
61
|
+
display: grid;
|
|
62
|
+
grid-template-columns: 1fr;
|
|
63
|
+
gap: 3px;
|
|
64
|
+
}
|
|
65
|
+
.designer-toolbox button {
|
|
66
|
+
text-align: start;
|
|
67
|
+
padding: 7px;
|
|
68
|
+
background: Canvas;
|
|
69
|
+
color: CanvasText;
|
|
70
|
+
border: 1px solid GrayText;
|
|
71
|
+
font: inherit;
|
|
72
|
+
}
|
|
73
|
+
.designer-toolbox button:hover,
|
|
74
|
+
.designer-toolbox button:focus-visible {
|
|
75
|
+
background: var(--color-primary);
|
|
76
|
+
color: var(--color-on-primary);
|
|
77
|
+
}
|
|
78
|
+
.ui-designer [role='tree'],
|
|
79
|
+
.ui-designer [role='group'] {
|
|
80
|
+
margin: 0;
|
|
81
|
+
padding: 0;
|
|
82
|
+
list-style: none;
|
|
83
|
+
}
|
|
84
|
+
.ui-designer [role='treeitem'] {
|
|
85
|
+
outline-offset: -2px;
|
|
86
|
+
}
|
|
87
|
+
.ui-designer [role='treeitem'] > [role='group'] {
|
|
88
|
+
padding-inline-start: 14px;
|
|
89
|
+
}
|
|
90
|
+
.outline-row {
|
|
91
|
+
display: flex;
|
|
92
|
+
gap: 5px;
|
|
93
|
+
padding: 6px 2px;
|
|
94
|
+
white-space: nowrap;
|
|
95
|
+
}
|
|
96
|
+
.ui-designer [role='treeitem'][aria-selected='true'] > .outline-row {
|
|
97
|
+
background: var(--color-primary);
|
|
98
|
+
color: var(--color-on-primary);
|
|
99
|
+
}
|
|
100
|
+
.ui-designer [data-link-id='properties'] table {
|
|
101
|
+
border-collapse: collapse;
|
|
102
|
+
width: 100%;
|
|
103
|
+
}
|
|
104
|
+
.ui-designer [data-link-id='properties'] th,
|
|
105
|
+
.ui-designer [data-link-id='properties'] td {
|
|
106
|
+
padding: 4px;
|
|
107
|
+
text-align: start;
|
|
108
|
+
}
|
|
109
|
+
.ui-designer [data-link-id='properties'] .resolved,
|
|
110
|
+
.ui-designer [data-link-id='properties'] th:nth-child(n + 3),
|
|
111
|
+
.ui-designer [data-link-id='properties'] td:nth-child(n + 3) {
|
|
112
|
+
display: none;
|
|
113
|
+
}
|
|
114
|
+
.ui-designer .editor {
|
|
115
|
+
display: flex;
|
|
116
|
+
gap: 3px;
|
|
117
|
+
}
|
|
118
|
+
.ui-designer .editor input {
|
|
119
|
+
min-width: 0;
|
|
120
|
+
width: 100%;
|
|
121
|
+
box-sizing: border-box;
|
|
122
|
+
}
|
|
123
|
+
.ui-designer .editor input,
|
|
124
|
+
.ui-designer .editor select {
|
|
125
|
+
font: inherit;
|
|
126
|
+
padding: 4px;
|
|
127
|
+
background: Canvas;
|
|
128
|
+
color: CanvasText;
|
|
129
|
+
}
|
|
130
|
+
.ui-designer [data-link-id='source'] {
|
|
131
|
+
display: flex;
|
|
132
|
+
flex-direction: column;
|
|
133
|
+
}
|
|
134
|
+
.ui-designer [data-link-id='source'][hidden] {
|
|
135
|
+
display: none;
|
|
136
|
+
}
|
|
137
|
+
.designer-source {
|
|
138
|
+
width: 100%;
|
|
139
|
+
min-height: 110px;
|
|
140
|
+
flex: 1;
|
|
141
|
+
box-sizing: border-box;
|
|
142
|
+
font:
|
|
143
|
+
13px/1.5 ui-monospace,
|
|
144
|
+
monospace;
|
|
145
|
+
background: Canvas;
|
|
146
|
+
color: CanvasText;
|
|
147
|
+
}
|
|
148
|
+
.ui-designer .designer-source .cm-editor {
|
|
149
|
+
min-height: 110px;
|
|
150
|
+
height: 100%;
|
|
151
|
+
}
|
|
152
|
+
.designer-source .cm-gutters {
|
|
153
|
+
background: Canvas;
|
|
154
|
+
color: CanvasText;
|
|
155
|
+
}
|
|
156
|
+
.designer-source-error {
|
|
157
|
+
margin: 0;
|
|
158
|
+
color: #b3261e;
|
|
159
|
+
}
|
|
160
|
+
.designer-status {
|
|
161
|
+
padding: 5px 12px;
|
|
162
|
+
border-top: 1px solid GrayText;
|
|
163
|
+
min-height: 20px;
|
|
164
|
+
}
|
|
165
|
+
.designer-decorations {
|
|
166
|
+
pointer-events: none;
|
|
167
|
+
}
|
|
168
|
+
.designer-drop,
|
|
169
|
+
.designer-guide,
|
|
170
|
+
.designer-marquee {
|
|
171
|
+
position: fixed;
|
|
172
|
+
pointer-events: none;
|
|
173
|
+
box-sizing: border-box;
|
|
174
|
+
z-index: 2147483647;
|
|
175
|
+
}
|
|
176
|
+
.designer-drop {
|
|
177
|
+
border: 2px solid #2457b3;
|
|
178
|
+
background: rgb(36 87 179 / 0.12);
|
|
179
|
+
}
|
|
180
|
+
.designer-drop.refused {
|
|
181
|
+
border: 3px dashed #b3261e;
|
|
182
|
+
background: rgb(179 38 30 / 0.16);
|
|
183
|
+
}
|
|
184
|
+
.designer-guide {
|
|
185
|
+
background: #b32677;
|
|
186
|
+
}
|
|
187
|
+
.designer-marquee {
|
|
188
|
+
border: 1px solid #2457b3;
|
|
189
|
+
background: rgb(36 87 179 / 0.12);
|
|
190
|
+
}
|
|
191
|
+
.designer-resize {
|
|
192
|
+
position: fixed;
|
|
193
|
+
width: 12px;
|
|
194
|
+
height: 12px;
|
|
195
|
+
padding: 0;
|
|
196
|
+
border: 2px solid Canvas;
|
|
197
|
+
background: #2457b3;
|
|
198
|
+
z-index: 2147483647;
|
|
199
|
+
cursor: nwse-resize;
|
|
200
|
+
touch-action: none;
|
|
201
|
+
}
|
|
202
|
+
.ui-designer :focus-visible {
|
|
203
|
+
outline: 3px solid Highlight;
|
|
204
|
+
}
|
|
205
|
+
@media (prefers-color-scheme: dark) {
|
|
206
|
+
.ui-designer {
|
|
207
|
+
--color-primary: #a8c7fa;
|
|
208
|
+
--color-on-primary: #102e60;
|
|
209
|
+
}
|
|
210
|
+
.designer-source-error {
|
|
211
|
+
color: #ffb4ab;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
@media (prefers-reduced-motion: reduce) {
|
|
215
|
+
.ui-designer * {
|
|
216
|
+
transition: none !important;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
@media (forced-colors: active) {
|
|
220
|
+
.designer-toolbox button:hover,
|
|
221
|
+
.designer-toolbox button:focus-visible,
|
|
222
|
+
.ui-designer [role='treeitem'][aria-selected='true'] > .outline-row {
|
|
223
|
+
background: Highlight;
|
|
224
|
+
color: HighlightText;
|
|
225
|
+
}
|
|
226
|
+
.designer-guide {
|
|
227
|
+
background: Highlight;
|
|
228
|
+
}
|
|
229
|
+
.designer-drop.refused {
|
|
230
|
+
border-color: Mark;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
.designer-timeline {
|
|
235
|
+
--timeline-accent: #2457b3;
|
|
236
|
+
}
|
|
237
|
+
.designer-timeline [data-link-id='timeline-toolbar'] {
|
|
238
|
+
flex-wrap: wrap;
|
|
239
|
+
}
|
|
240
|
+
.timeline-viewport {
|
|
241
|
+
overflow-x: auto;
|
|
242
|
+
min-height: 150px;
|
|
243
|
+
padding-bottom: 6px;
|
|
244
|
+
}
|
|
245
|
+
.timeline-row {
|
|
246
|
+
display: flex;
|
|
247
|
+
height: 32px;
|
|
248
|
+
border-bottom: 1px solid GrayText;
|
|
249
|
+
}
|
|
250
|
+
.timeline-label {
|
|
251
|
+
position: sticky;
|
|
252
|
+
left: 0;
|
|
253
|
+
z-index: 3;
|
|
254
|
+
flex: 0 0 200px;
|
|
255
|
+
box-sizing: border-box;
|
|
256
|
+
width: 200px;
|
|
257
|
+
background: Canvas;
|
|
258
|
+
color: CanvasText;
|
|
259
|
+
padding: 4px 8px;
|
|
260
|
+
text-align: start;
|
|
261
|
+
border: 0;
|
|
262
|
+
font: inherit;
|
|
263
|
+
}
|
|
264
|
+
.timeline-lane {
|
|
265
|
+
flex: 1;
|
|
266
|
+
position: relative;
|
|
267
|
+
touch-action: none;
|
|
268
|
+
}
|
|
269
|
+
.timeline-ruler {
|
|
270
|
+
cursor: crosshair;
|
|
271
|
+
}
|
|
272
|
+
.timeline-ruler > span {
|
|
273
|
+
position: absolute;
|
|
274
|
+
font-size: 12px;
|
|
275
|
+
}
|
|
276
|
+
.timeline-marker,
|
|
277
|
+
.timeline-end {
|
|
278
|
+
position: absolute;
|
|
279
|
+
top: 3px;
|
|
280
|
+
transform: translateX(-50%);
|
|
281
|
+
width: 26px;
|
|
282
|
+
height: 26px;
|
|
283
|
+
padding: 0;
|
|
284
|
+
background: Canvas;
|
|
285
|
+
color: CanvasText;
|
|
286
|
+
border: 1px solid GrayText;
|
|
287
|
+
cursor: ew-resize;
|
|
288
|
+
z-index: 2;
|
|
289
|
+
touch-action: none;
|
|
290
|
+
}
|
|
291
|
+
.timeline-marker[aria-pressed='true'] {
|
|
292
|
+
background: var(--timeline-accent);
|
|
293
|
+
color: white;
|
|
294
|
+
}
|
|
295
|
+
.timeline-playhead {
|
|
296
|
+
position: absolute;
|
|
297
|
+
top: 0;
|
|
298
|
+
bottom: 0;
|
|
299
|
+
border-left: 2px solid var(--timeline-accent);
|
|
300
|
+
pointer-events: none;
|
|
301
|
+
z-index: 1;
|
|
302
|
+
}
|
|
303
|
+
@media (prefers-color-scheme: dark) {
|
|
304
|
+
.designer-timeline {
|
|
305
|
+
--timeline-accent: #86b7ff;
|
|
306
|
+
}
|
|
307
|
+
.timeline-marker[aria-pressed='true'] {
|
|
308
|
+
color: #111;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
.ui-designer [data-link-id='properties'] > label {
|
|
312
|
+
display: flex;
|
|
313
|
+
flex-direction: column;
|
|
314
|
+
gap: 4px;
|
|
315
|
+
margin-bottom: 10px;
|
|
316
|
+
}
|
package/src/designer.js
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/** A designer made from the framework's LiNo dock, layout and control renderers. */
|
|
2
|
+
import { parseOrThrow } from '@link-foundation/ui-core';
|
|
3
|
+
import { createStore } from '@link-foundation/ui-store';
|
|
4
|
+
import { render } from '@link-foundation/ui-dom';
|
|
5
|
+
import { CONTROL_KIND_SPECS } from '@link-foundation/ui-components/controls';
|
|
6
|
+
import { createConfig, persistUserLayer } from '@link-foundation/ui-config';
|
|
7
|
+
import { defaultPolicy, parseDevModePolicy } from '@link-foundation/ui-devmode';
|
|
8
|
+
import { createCatalog, designerVocabulary } from './catalog.js';
|
|
9
|
+
import { createDocumentSession } from './sync.js';
|
|
10
|
+
import { createSelection } from './selection.js';
|
|
11
|
+
import { createOutline } from './panels.js';
|
|
12
|
+
import { mountCanvas } from './canvas.js';
|
|
13
|
+
import { createEditing } from './editing.js';
|
|
14
|
+
import { createActions, keyboard } from './actions.js';
|
|
15
|
+
import { element, listen } from './dom.js';
|
|
16
|
+
import { DESIGNER_LAYOUT } from './layout-text.js';
|
|
17
|
+
import { mountSourcePanel } from './source-panel.js';
|
|
18
|
+
import { mountTimeline } from './timeline/timeline.js';
|
|
19
|
+
|
|
20
|
+
function browserStorage(window) {
|
|
21
|
+
try {
|
|
22
|
+
return window.localStorage;
|
|
23
|
+
} catch {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function readSaved(storage, key) {
|
|
28
|
+
try {
|
|
29
|
+
return storage?.getItem(key);
|
|
30
|
+
} catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function createContext(options) {
|
|
35
|
+
const {
|
|
36
|
+
root,
|
|
37
|
+
documentText,
|
|
38
|
+
storageKey = 'link-ui-designer',
|
|
39
|
+
catalog = createCatalog(),
|
|
40
|
+
} = options;
|
|
41
|
+
const document = root.ownerDocument;
|
|
42
|
+
const window = document.defaultView;
|
|
43
|
+
const storage =
|
|
44
|
+
options.storage === undefined ? browserStorage(window) : options.storage;
|
|
45
|
+
const policy =
|
|
46
|
+
typeof options.policy === 'string'
|
|
47
|
+
? parseDevModePolicy(options.policy)
|
|
48
|
+
: (options.policy ?? defaultPolicy());
|
|
49
|
+
if (!policy.enabled) {
|
|
50
|
+
throw new Error('The site policy disables the designer');
|
|
51
|
+
}
|
|
52
|
+
let session;
|
|
53
|
+
try {
|
|
54
|
+
session = createDocumentSession(
|
|
55
|
+
readSaved(storage, `${storageKey}.draft`) ?? documentText
|
|
56
|
+
);
|
|
57
|
+
} catch {
|
|
58
|
+
session = createDocumentSession(documentText);
|
|
59
|
+
}
|
|
60
|
+
const context = {
|
|
61
|
+
options,
|
|
62
|
+
root,
|
|
63
|
+
document,
|
|
64
|
+
window,
|
|
65
|
+
storage,
|
|
66
|
+
storageKey,
|
|
67
|
+
policy,
|
|
68
|
+
session,
|
|
69
|
+
store: session.store,
|
|
70
|
+
catalog,
|
|
71
|
+
selection: createSelection(),
|
|
72
|
+
controller: new window.AbortController(),
|
|
73
|
+
modeValue: 'design',
|
|
74
|
+
snapThreshold: options.snapThreshold ?? 6,
|
|
75
|
+
};
|
|
76
|
+
context.mode = () => context.modeValue;
|
|
77
|
+
return context;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function mountShell(context) {
|
|
81
|
+
const { root, options, storage, storageKey } = context;
|
|
82
|
+
const shellStore = createStore({
|
|
83
|
+
document: parseOrThrow(options.layoutText ?? DESIGNER_LAYOUT, {
|
|
84
|
+
vocabulary: designerVocabulary(),
|
|
85
|
+
}),
|
|
86
|
+
});
|
|
87
|
+
const config = createConfig({ document: shellStore.toDocument() });
|
|
88
|
+
const persistence = storage
|
|
89
|
+
? persistUserLayer(config, storage, `${storageKey}.user`)
|
|
90
|
+
: null;
|
|
91
|
+
const layoutStorage = {
|
|
92
|
+
getItem: (key) => config.resolve(key, 'note')?.value?.[0] ?? null,
|
|
93
|
+
setItem: (key, text) => config.set('user', key, 'note', [text]),
|
|
94
|
+
};
|
|
95
|
+
const shell = render(root, shellStore, {
|
|
96
|
+
kinds: CONTROL_KIND_SPECS,
|
|
97
|
+
setTitle: false,
|
|
98
|
+
layout: { storage: layoutStorage },
|
|
99
|
+
isAction: (name) => name === 'designer',
|
|
100
|
+
onAction: (detail) => {
|
|
101
|
+
if (detail.action[0] === 'designer') {
|
|
102
|
+
void context.command(detail.action[1]);
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
root.classList.add('ui-designer');
|
|
107
|
+
root.dataset.mode = 'design';
|
|
108
|
+
return { shellStore, shell, persistence };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function mountPanels(context) {
|
|
112
|
+
const { root, document, shell, session, storageKey, store, options } =
|
|
113
|
+
context;
|
|
114
|
+
const status = element(
|
|
115
|
+
document,
|
|
116
|
+
'output',
|
|
117
|
+
{ class: 'designer-status', role: 'status', 'aria-live': 'polite' },
|
|
118
|
+
'Design mode'
|
|
119
|
+
);
|
|
120
|
+
const error = element(document, 'p', {
|
|
121
|
+
class: 'designer-source-error',
|
|
122
|
+
role: 'alert',
|
|
123
|
+
id: `${storageKey}-error`,
|
|
124
|
+
});
|
|
125
|
+
const report = (message) => {
|
|
126
|
+
status.textContent = message;
|
|
127
|
+
};
|
|
128
|
+
const source = mountSourcePanel(shell.nodeFor('source'), {
|
|
129
|
+
text: session.getText(),
|
|
130
|
+
error,
|
|
131
|
+
onChange: (text) => context.editSource(text),
|
|
132
|
+
readOnly: !context.policy.writeLayers.length,
|
|
133
|
+
report,
|
|
134
|
+
});
|
|
135
|
+
const file = element(document, 'input', {
|
|
136
|
+
type: 'file',
|
|
137
|
+
accept: '.lino,text/plain',
|
|
138
|
+
'aria-label': 'Open LiNo file',
|
|
139
|
+
hidden: '',
|
|
140
|
+
});
|
|
141
|
+
const canvas = element(document, 'div', {
|
|
142
|
+
class: 'designer-canvas',
|
|
143
|
+
tabindex: 0,
|
|
144
|
+
role: 'region',
|
|
145
|
+
'aria-label': 'Design canvas',
|
|
146
|
+
});
|
|
147
|
+
shell.nodeFor('canvas').append(canvas);
|
|
148
|
+
root.append(status, file);
|
|
149
|
+
const handle = render(canvas, store, {
|
|
150
|
+
kinds: CONTROL_KIND_SPECS,
|
|
151
|
+
setTitle: false,
|
|
152
|
+
onAction: options.onAction,
|
|
153
|
+
});
|
|
154
|
+
return {
|
|
155
|
+
status,
|
|
156
|
+
error,
|
|
157
|
+
source,
|
|
158
|
+
file,
|
|
159
|
+
canvas,
|
|
160
|
+
handle,
|
|
161
|
+
report,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* @param {{root: HTMLElement, documentText: string, storage?: Storage|null,
|
|
167
|
+
* storageKey?: string, catalog?: Map<string, object>, policy?: object|string,
|
|
168
|
+
* layoutText?: string, snapThreshold?: number, onAction?: Function,
|
|
169
|
+
* resolveToken?: (path: string) => unknown, timelineFps?: number,
|
|
170
|
+
* trace?: (event: string, detail: object) => void}} options
|
|
171
|
+
* @returns {{ready: Promise<void>, getText: () => string, undo: () => boolean, redo: () => boolean,
|
|
172
|
+
* destroy: () => void, store: object, select: (id: string) => void,
|
|
173
|
+
* setMode: (mode: 'design'|'run') => void, editSource: (text: string) => object}}
|
|
174
|
+
*/
|
|
175
|
+
export function mountDesigner(options) {
|
|
176
|
+
const context = createContext(options);
|
|
177
|
+
Object.assign(context, mountShell(context));
|
|
178
|
+
Object.assign(context, mountPanels(context));
|
|
179
|
+
Object.assign(context, createEditing(context));
|
|
180
|
+
context.outline = createOutline(context.shell.nodeFor('outline'), context);
|
|
181
|
+
context.canvasController = mountCanvas(context);
|
|
182
|
+
createToolbox(context.shell.nodeFor('toolbox'), context);
|
|
183
|
+
context.command = createActions(context);
|
|
184
|
+
context.timeline = mountTimeline(context.shell.nodeFor('timeline'), context);
|
|
185
|
+
const {
|
|
186
|
+
root,
|
|
187
|
+
source,
|
|
188
|
+
file,
|
|
189
|
+
controller,
|
|
190
|
+
session,
|
|
191
|
+
storage,
|
|
192
|
+
storageKey,
|
|
193
|
+
report,
|
|
194
|
+
refresh,
|
|
195
|
+
editSource,
|
|
196
|
+
} = context;
|
|
197
|
+
const unsubscribe = session.subscribe(() => {
|
|
198
|
+
try {
|
|
199
|
+
storage?.setItem(`${storageKey}.draft`, session.getText());
|
|
200
|
+
} catch (error) {
|
|
201
|
+
report(`Draft could not be saved: ${error.message}`);
|
|
202
|
+
}
|
|
203
|
+
refresh();
|
|
204
|
+
});
|
|
205
|
+
listen(
|
|
206
|
+
file,
|
|
207
|
+
'change',
|
|
208
|
+
async () => {
|
|
209
|
+
const opened = file.files[0];
|
|
210
|
+
if (opened) {
|
|
211
|
+
const text = await opened.text();
|
|
212
|
+
editSource(text);
|
|
213
|
+
file.value = '';
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
controller
|
|
217
|
+
);
|
|
218
|
+
listen(root, 'keydown', (event) => keyboard(event, context), controller);
|
|
219
|
+
refresh();
|
|
220
|
+
return {
|
|
221
|
+
ready: source.ready,
|
|
222
|
+
getText: session.getText,
|
|
223
|
+
store: session.store,
|
|
224
|
+
select: (id) => context.choose(id),
|
|
225
|
+
setMode: context.setMode,
|
|
226
|
+
editSource,
|
|
227
|
+
undo: session.undo,
|
|
228
|
+
redo: session.redo,
|
|
229
|
+
destroy() {
|
|
230
|
+
context.timeline?.destroy();
|
|
231
|
+
context.comments?.destroy();
|
|
232
|
+
controller.abort();
|
|
233
|
+
unsubscribe();
|
|
234
|
+
context.canvasController.destroy();
|
|
235
|
+
source.destroy();
|
|
236
|
+
context.handle.destroy();
|
|
237
|
+
context.shell.destroy();
|
|
238
|
+
context.persistence?.stop();
|
|
239
|
+
session.destroy();
|
|
240
|
+
context.status.remove();
|
|
241
|
+
file.remove();
|
|
242
|
+
root.classList.remove('ui-designer');
|
|
243
|
+
delete root.dataset.mode;
|
|
244
|
+
},
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function createToolbox(panel, context) {
|
|
249
|
+
const { document, catalog, controller } = context;
|
|
250
|
+
const list = element(document, 'div', {
|
|
251
|
+
class: 'designer-toolbox',
|
|
252
|
+
role: 'group',
|
|
253
|
+
'aria-label': 'Components',
|
|
254
|
+
});
|
|
255
|
+
for (const entry of catalog.values()) {
|
|
256
|
+
const button = element(
|
|
257
|
+
document,
|
|
258
|
+
'button',
|
|
259
|
+
{ type: 'button', 'data-component': entry.type },
|
|
260
|
+
`${entry.icon} ${entry.name}`
|
|
261
|
+
);
|
|
262
|
+
listen(button, 'click', () => context.insert(entry.type), controller);
|
|
263
|
+
list.append(button);
|
|
264
|
+
}
|
|
265
|
+
panel.append(list);
|
|
266
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
designer: document
|
|
2
|
+
title 'Links UI designer'
|
|
3
|
+
toolbar: stack
|
|
4
|
+
direction horizontal
|
|
5
|
+
gap 4px
|
|
6
|
+
mode: button
|
|
7
|
+
label Run
|
|
8
|
+
on press
|
|
9
|
+
designer mode
|
|
10
|
+
undo: button
|
|
11
|
+
label Undo
|
|
12
|
+
on press
|
|
13
|
+
designer undo
|
|
14
|
+
redo: button
|
|
15
|
+
label Redo
|
|
16
|
+
on press
|
|
17
|
+
designer redo
|
|
18
|
+
duplicate: button
|
|
19
|
+
label Duplicate
|
|
20
|
+
on press
|
|
21
|
+
designer duplicate
|
|
22
|
+
delete: button
|
|
23
|
+
label Delete
|
|
24
|
+
on press
|
|
25
|
+
designer delete
|
|
26
|
+
copy: button
|
|
27
|
+
label Copy
|
|
28
|
+
on press
|
|
29
|
+
designer copy
|
|
30
|
+
cut: button
|
|
31
|
+
label Cut
|
|
32
|
+
on press
|
|
33
|
+
designer cut
|
|
34
|
+
paste: button
|
|
35
|
+
label Paste
|
|
36
|
+
on press
|
|
37
|
+
designer paste
|
|
38
|
+
open: button
|
|
39
|
+
label Open
|
|
40
|
+
on press
|
|
41
|
+
designer open
|
|
42
|
+
save: button
|
|
43
|
+
label Save
|
|
44
|
+
on press
|
|
45
|
+
designer save
|
|
46
|
+
comments: button
|
|
47
|
+
label 'Comment on UI'
|
|
48
|
+
on press
|
|
49
|
+
designer comments
|
|
50
|
+
copy-source: button
|
|
51
|
+
label 'Copy source'
|
|
52
|
+
on press
|
|
53
|
+
designer copy-source
|
|
54
|
+
workspace: split
|
|
55
|
+
direction column
|
|
56
|
+
label Workspace
|
|
57
|
+
sizes 72 28
|
|
58
|
+
min 35 12
|
|
59
|
+
max 88 65
|
|
60
|
+
remember-size workspace
|
|
61
|
+
horizontal: split
|
|
62
|
+
direction row
|
|
63
|
+
label Panels
|
|
64
|
+
sizes 22 48 30
|
|
65
|
+
min 12 20 18
|
|
66
|
+
max 45 70 50
|
|
67
|
+
remember-size horizontal
|
|
68
|
+
left-dock: dock
|
|
69
|
+
label 'Toolbox and Outline'
|
|
70
|
+
persist left-dock
|
|
71
|
+
left-region: region
|
|
72
|
+
side center
|
|
73
|
+
panels toolbox outline
|
|
74
|
+
toolbox: panel
|
|
75
|
+
title Toolbox
|
|
76
|
+
outline: panel
|
|
77
|
+
title Outline
|
|
78
|
+
center-dock: dock
|
|
79
|
+
label Canvas
|
|
80
|
+
persist center-dock
|
|
81
|
+
center-region: region
|
|
82
|
+
side center
|
|
83
|
+
panels canvas
|
|
84
|
+
canvas: panel
|
|
85
|
+
title Canvas
|
|
86
|
+
closable false
|
|
87
|
+
right-dock: dock
|
|
88
|
+
label Properties
|
|
89
|
+
persist right-dock
|
|
90
|
+
right-region: region
|
|
91
|
+
side center
|
|
92
|
+
panels properties
|
|
93
|
+
properties: panel
|
|
94
|
+
title Properties
|
|
95
|
+
bottom-dock: dock
|
|
96
|
+
label Source
|
|
97
|
+
persist bottom-dock
|
|
98
|
+
bottom-region: region
|
|
99
|
+
side center
|
|
100
|
+
panels source timeline
|
|
101
|
+
source: panel
|
|
102
|
+
title Source
|
|
103
|
+
timeline: panel
|
|
104
|
+
title Timeline
|
package/src/dom.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Small DOM helpers scoped to one designer instance. */
|
|
2
|
+
export function element(document, tag, attributes = {}, text) {
|
|
3
|
+
const node = document.createElement(tag);
|
|
4
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
5
|
+
node.setAttribute(key, String(value));
|
|
6
|
+
}
|
|
7
|
+
if (text !== undefined) {
|
|
8
|
+
node.textContent = text;
|
|
9
|
+
}
|
|
10
|
+
return node;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const editable = (target) =>
|
|
14
|
+
!!target?.closest?.('input,textarea,select,[contenteditable=true]');
|
|
15
|
+
|
|
16
|
+
/** Listen with one lifetime controller, including events attached to the document. */
|
|
17
|
+
export function listen(target, type, callback, controller, capture = false) {
|
|
18
|
+
target.addEventListener(type, callback, {
|
|
19
|
+
signal: controller.signal,
|
|
20
|
+
capture,
|
|
21
|
+
});
|
|
22
|
+
}
|