@getcortexlabs/create-mavis 0.1.0-rc.13 → 0.1.0-rc.15
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 +44 -7
- package/package.json +4 -2
- package/src/adapters.mjs +56 -20
- package/src/add-desktop.mjs +308 -0
- package/src/add-macos.mjs +386 -0
- package/src/capabilities.mjs +352 -85
- package/src/cli.mjs +181 -9
- package/src/desktop.mjs +155 -0
- package/src/doctor.mjs +181 -18
- package/src/macos-capabilities.generated.mjs +4190 -0
- package/src/macos.mjs +147 -29
- package/src/migrate-directory.mjs +121 -0
- package/src/native-framework.mjs +144 -0
- package/src/portability.mjs +123 -5
- package/src/scaffold.mjs +59 -11
- package/src/ui.mjs +69 -12
- package/templates/desktop/common/LICENSE +21 -0
- package/templates/desktop/common/build.mjs +58 -0
- package/templates/desktop/common/src/components.ts +60 -0
- package/templates/desktop/common/src/contract.mjs +35 -0
- package/templates/desktop/common/src/renderer.ts +76 -0
- package/templates/desktop/common/src/storage.ts +29 -0
- package/templates/desktop/directory/main.ts +35 -0
- package/templates/desktop/macos/launch.mjs +6 -0
- package/templates/desktop/macos/package.mjs +114 -0
- package/templates/desktop/macos/src/host.mjs +468 -0
- package/templates/desktop/macos/src/motion.mjs +51 -0
- package/templates/desktop/welcome/Welcome.vue +56 -0
- package/templates/desktop/welcome/main.ts +24 -0
- package/templates/desktop/windows/NativeScript-LICENSE +19 -0
- package/templates/desktop/windows/launch.mjs +16 -0
- package/templates/desktop/windows/package.mjs +54 -0
- package/templates/desktop/windows/prepare-host.mjs +73 -0
- package/templates/desktop/windows/src/host.mjs +277 -0
- package/templates/directory/host/directory-storage.ts +78 -0
- package/templates/directory/macos/DirectoryStorage.swift +68 -0
- package/templates/directory/mobile/src/app.ts +11 -8
- package/templates/directory/nuxt/app/plugins/mavis.ts +11 -8
- package/templates/directory/shared/Edit.vue +8 -5
- package/templates/directory/shared/directory-store.ts +42 -46
- package/templates/directory/vite/src/main.ts +11 -8
- package/templates/macos/examples/tasks/shared/TaskDetail.lite.tsx +2 -2
- package/templates/macos/examples/tasks/shared/Tasks.lite.tsx +2 -2
- package/templates/macos/examples/tasks/shared/types.ts +1 -0
- package/templates/macos/mobile/src/App.vue +4 -2
- package/templates/macos/native/Package.swift +3 -1
- package/templates/macos/native/Sources/MavisDesktop/App.swift +26 -11
- package/templates/macos/native/Sources/MavisDesktop/Fonts/LICENSE +45 -0
- package/templates/macos/native/Sources/MavisDesktop/Fonts/lucide.ttf +0 -0
- package/templates/macos/scripts/generate.mjs +3 -26
- package/templates/macos/scripts/macos-manifest.mjs +33 -0
- package/templates/macos/scripts/macos.mjs +20 -18
- package/templates/macos/web/index.html +1 -1
- package/templates/macos/web/src/main.js +176 -3
- package/templates/macos/web/src/mavis.js +2 -0
- package/templates/macos/web/src/style.css +2 -1
- package/templates/macos/web/vite.config.mjs +12 -1
- package/templates/migrations/directory-rc13.json +36 -0
- package/templates/mobile/src/mavis.ts +2 -82
- package/templates/mobile/webpack.config.js +4 -0
- package/templates/native-framework/angular/screen.ts +84 -0
- package/templates/native-framework/common/nativescript.config.ts +6 -0
- package/templates/native-framework/common/src/app.ts +5 -0
- package/templates/native-framework/common/src/model.ts +40 -0
- package/templates/native-framework/common/src/references.d.ts +8 -0
- package/templates/native-framework/common/tsconfig.json +16 -0
- package/templates/native-framework/common/webpack.config.js +67 -0
- package/templates/native-framework/plain/screen.ts +102 -0
- package/templates/native-framework/react/screen.ts +83 -0
- package/templates/native-framework/solid/screen.ts +111 -0
- package/templates/native-framework/svelte/Welcome.svelte +26 -0
- package/templates/native-framework/svelte/screen.ts +14 -0
- package/templates/native-framework/svelte-tooling/svelte.config.js +20 -0
- package/templates/nuxt/app/mavis.ts +2 -84
- package/templates/vite/src/mavis.ts +2 -84
- package/templates/macos/scripts/portable/emit-swift.mjs +0 -1287
- package/templates/macos/scripts/portable/emit-vue.mjs +0 -615
- package/templates/macos/scripts/portable/index.mjs +0 -95
- package/templates/macos/scripts/portable/model.mjs +0 -1441
- package/templates/macos/scripts/portable/program.mjs +0 -163
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
import { nativeProps } from './contract.mjs'
|
|
2
|
+
import { mavis, midnight } from '@getcortexlabs/mavis-core'
|
|
3
|
+
import { opacityMotion } from './motion.mjs'
|
|
4
|
+
|
|
5
|
+
const rect = (x, y, width, height) => ({ origin: { x, y }, size: { width, height } })
|
|
6
|
+
const emit = (listener, ...args) => {
|
|
7
|
+
for (const fn of Array.isArray(listener) ? listener : [listener])
|
|
8
|
+
if (typeof fn === 'function') fn(...args)
|
|
9
|
+
}
|
|
10
|
+
const nativeColor = (hex) => {
|
|
11
|
+
const rgb = Number.parseInt(hex.replace('#', '').slice(0, 6), 16)
|
|
12
|
+
return NSColor.colorWithSRGBRedGreenBlueAlpha(
|
|
13
|
+
(rgb >> 16) / 255,
|
|
14
|
+
((rgb >> 8) & 255) / 255,
|
|
15
|
+
(rgb & 255) / 255,
|
|
16
|
+
1,
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
class MavisAppKitView extends NSView {
|
|
21
|
+
static {
|
|
22
|
+
NativeClass(this)
|
|
23
|
+
}
|
|
24
|
+
// The bridge overrides the Objective-C property name, not its isFlipped selector.
|
|
25
|
+
get flipped() {
|
|
26
|
+
return true
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
class MavisAppKitCard extends NSButton {
|
|
30
|
+
static {
|
|
31
|
+
NativeClass(this)
|
|
32
|
+
}
|
|
33
|
+
hitTest(point) {
|
|
34
|
+
return super.hitTest(point) ? this : null
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
class MavisAppKitAction extends NSObject {
|
|
38
|
+
static ObjCExposedMethods = {
|
|
39
|
+
activate: { returns: interop.types.void, params: [interop.types.id] },
|
|
40
|
+
}
|
|
41
|
+
static {
|
|
42
|
+
NativeClass(this)
|
|
43
|
+
}
|
|
44
|
+
activate() {
|
|
45
|
+
this.callback?.()
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
class MavisAppKitInputDelegate extends NSObject {
|
|
49
|
+
static ObjCProtocols = [NSTextFieldDelegate]
|
|
50
|
+
static {
|
|
51
|
+
NativeClass(this)
|
|
52
|
+
}
|
|
53
|
+
controlTextDidChange() {
|
|
54
|
+
this.change?.()
|
|
55
|
+
}
|
|
56
|
+
controlTextViewDoCommandBySelector(_control, _editor, selector) {
|
|
57
|
+
if (selector === 'insertNewline:') {
|
|
58
|
+
this.submit?.()
|
|
59
|
+
return true
|
|
60
|
+
}
|
|
61
|
+
if (selector === 'cancelOperation:') {
|
|
62
|
+
this.escape?.()
|
|
63
|
+
return true
|
|
64
|
+
}
|
|
65
|
+
return false
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
class MavisAppKitWindowDelegate extends NSObject {
|
|
69
|
+
static ObjCProtocols = [NSWindowDelegate]
|
|
70
|
+
static {
|
|
71
|
+
NativeClass(this)
|
|
72
|
+
}
|
|
73
|
+
windowDidResize() {
|
|
74
|
+
this.resize?.()
|
|
75
|
+
}
|
|
76
|
+
windowWillClose() {
|
|
77
|
+
this.close?.()
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Small, explicit component host for the desktop starter, not the full Mavis renderer. */
|
|
82
|
+
export function createHost({ title = '__MAVIS_NAME__', onClose = () => {} } = {}) {
|
|
83
|
+
const app = NSApplication.sharedApplication
|
|
84
|
+
app.setActivationPolicy(NSApplicationActivationPolicy.Regular)
|
|
85
|
+
const window = NSWindow.alloc().initWithContentRectStyleMaskBackingDefer(
|
|
86
|
+
rect(0, 0, 780, 620),
|
|
87
|
+
NSWindowStyleMask.Titled |
|
|
88
|
+
NSWindowStyleMask.Closable |
|
|
89
|
+
NSWindowStyleMask.Miniaturizable |
|
|
90
|
+
NSWindowStyleMask.Resizable,
|
|
91
|
+
NSBackingStoreType.Buffered,
|
|
92
|
+
false,
|
|
93
|
+
)
|
|
94
|
+
window.title = title
|
|
95
|
+
window.releasedWhenClosed = false
|
|
96
|
+
window.minSize = { width: 360, height: 380 }
|
|
97
|
+
const rootView = MavisAppKitView.alloc().initWithFrame(rect(0, 0, 780, 620))
|
|
98
|
+
window.contentView = rootView
|
|
99
|
+
const root = {
|
|
100
|
+
kind: 'root',
|
|
101
|
+
text: '',
|
|
102
|
+
props: {},
|
|
103
|
+
children: [],
|
|
104
|
+
parent: null,
|
|
105
|
+
native: rootView,
|
|
106
|
+
content: rootView,
|
|
107
|
+
}
|
|
108
|
+
const nodes = new Set([root])
|
|
109
|
+
let theme = mavis,
|
|
110
|
+
closed = false,
|
|
111
|
+
scheduled = false,
|
|
112
|
+
pumpTimer
|
|
113
|
+
let reducedOverride = null
|
|
114
|
+
const reduced = () =>
|
|
115
|
+
reducedOverride ?? NSWorkspace.sharedWorkspace.accessibilityDisplayShouldReduceMotion
|
|
116
|
+
const actions = [] // Cocoa targets/delegates are weak. Retain until their owner is disposed.
|
|
117
|
+
const sheets = new Set()
|
|
118
|
+
const tokens = (key) => (typeof key === 'number' ? key : (theme.space[key] ?? 0))
|
|
119
|
+
const text = (node) => node.text || node.children.map(text).join('')
|
|
120
|
+
const setBackground = (view, color) => {
|
|
121
|
+
view.wantsLayer = true
|
|
122
|
+
view.layer.backgroundColor = nativeColor(color).CGColor
|
|
123
|
+
}
|
|
124
|
+
function action(target, callback) {
|
|
125
|
+
const delegate = MavisAppKitAction.new()
|
|
126
|
+
delegate.callback = callback
|
|
127
|
+
target.target = delegate
|
|
128
|
+
target.action = 'activate'
|
|
129
|
+
return delegate
|
|
130
|
+
}
|
|
131
|
+
function create(kind) {
|
|
132
|
+
if (
|
|
133
|
+
![
|
|
134
|
+
'#text',
|
|
135
|
+
'#comment',
|
|
136
|
+
'screen',
|
|
137
|
+
'column',
|
|
138
|
+
'row',
|
|
139
|
+
'grid',
|
|
140
|
+
'text',
|
|
141
|
+
'input',
|
|
142
|
+
'reveal',
|
|
143
|
+
'button',
|
|
144
|
+
'link',
|
|
145
|
+
'card',
|
|
146
|
+
].includes(kind)
|
|
147
|
+
)
|
|
148
|
+
throw new Error(`AppKit desktop host does not implement ${kind}`)
|
|
149
|
+
const node = { kind, text: '', props: {}, children: [], parent: null }
|
|
150
|
+
nodes.add(node)
|
|
151
|
+
if (kind[0] === '#') return node
|
|
152
|
+
if (kind === 'text') {
|
|
153
|
+
node.native = NSTextField.labelWithString('')
|
|
154
|
+
node.native.lineBreakMode = NSLineBreakMode.ByWordWrapping
|
|
155
|
+
node.native.maximumNumberOfLines = 0
|
|
156
|
+
} else if (kind === 'input') {
|
|
157
|
+
node.native = MavisAppKitView.new()
|
|
158
|
+
node.label = NSTextField.labelWithString('')
|
|
159
|
+
node.editor = NSTextField.new()
|
|
160
|
+
node.editor.bezelStyle = NSTextFieldBezelStyle.RoundedBezel
|
|
161
|
+
node.delegate = MavisAppKitInputDelegate.new()
|
|
162
|
+
node.delegate.change = () => emit(node.props['onUpdate:modelValue'], node.editor.stringValue)
|
|
163
|
+
node.delegate.submit = () => emit(node.props.onSubmit)
|
|
164
|
+
node.delegate.escape = () => emit(node.props.onEscape)
|
|
165
|
+
node.editor.delegate = node.delegate
|
|
166
|
+
node.native.addSubview(node.label)
|
|
167
|
+
node.native.addSubview(node.editor)
|
|
168
|
+
} else if (['button', 'link', 'card'].includes(kind)) {
|
|
169
|
+
node.native = kind === 'card' ? MavisAppKitCard.new() : NSButton.new()
|
|
170
|
+
node.native.setButtonType(NSButtonType.MomentaryPushIn)
|
|
171
|
+
node.native.bezelStyle = NSBezelStyle.Rounded
|
|
172
|
+
node.delegate = action(node.native, () => emit(node.props.onClick))
|
|
173
|
+
if (kind === 'link') node.native.bordered = false
|
|
174
|
+
if (kind === 'card') {
|
|
175
|
+
node.content = MavisAppKitView.new()
|
|
176
|
+
node.native.addSubview(node.content)
|
|
177
|
+
}
|
|
178
|
+
} else if (kind === 'screen') {
|
|
179
|
+
node.native = NSScrollView.new()
|
|
180
|
+
node.native.hasVerticalScroller = true
|
|
181
|
+
node.native.autohidesScrollers = true
|
|
182
|
+
node.native.drawsBackground = false
|
|
183
|
+
node.content = MavisAppKitView.new()
|
|
184
|
+
node.native.documentView = node.content
|
|
185
|
+
} else node.native = MavisAppKitView.new()
|
|
186
|
+
node.content ??= node.native
|
|
187
|
+
node.native.wantsLayer = true
|
|
188
|
+
node.dispose = () => {
|
|
189
|
+
node.motion?.cancel()
|
|
190
|
+
if (node.editor) node.editor.delegate = null
|
|
191
|
+
if (node.delegate) {
|
|
192
|
+
node.delegate.callback =
|
|
193
|
+
node.delegate.change =
|
|
194
|
+
node.delegate.submit =
|
|
195
|
+
node.delegate.escape =
|
|
196
|
+
null
|
|
197
|
+
if ('target' in node.native) node.native.target = null
|
|
198
|
+
node.delegate = null
|
|
199
|
+
}
|
|
200
|
+
nodes.delete(node)
|
|
201
|
+
}
|
|
202
|
+
return node
|
|
203
|
+
}
|
|
204
|
+
function update(node) {
|
|
205
|
+
if (!node.native || closed) return
|
|
206
|
+
const p = node.props,
|
|
207
|
+
view = node.native
|
|
208
|
+
for (const key of Object.keys(p))
|
|
209
|
+
if (!nativeProps(node.kind, 'macos').includes(key))
|
|
210
|
+
throw new Error(`AppKit desktop host does not implement ${node.kind}.${key}`)
|
|
211
|
+
const identifier = String(p.id ?? '')
|
|
212
|
+
view.accessibilityIdentifier = identifier
|
|
213
|
+
if (p.accessibilityLabel) view.accessibilityLabel = p.accessibilityLabel
|
|
214
|
+
if (node.kind === 'text') {
|
|
215
|
+
view.stringValue = p.text ?? text(node)
|
|
216
|
+
const size = { title: 28, heading: 20, caption: 12 }[p.variant] ?? 14
|
|
217
|
+
view.font =
|
|
218
|
+
p.variant === 'title' || p.variant === 'heading'
|
|
219
|
+
? NSFont.boldSystemFontOfSize(size)
|
|
220
|
+
: NSFont.systemFontOfSize(size)
|
|
221
|
+
view.textColor = nativeColor(theme.colors[p.tone] ?? theme.colors.text)
|
|
222
|
+
}
|
|
223
|
+
if (node.kind === 'input') {
|
|
224
|
+
node.label.stringValue = String(p.label ?? '')
|
|
225
|
+
node.label.textColor = nativeColor(theme.colors.text)
|
|
226
|
+
const value = String(p.modelValue ?? '')
|
|
227
|
+
// Re-rendering unrelated state must not reset the editor's selection/caret.
|
|
228
|
+
if (node.editor.stringValue !== value) node.editor.stringValue = value
|
|
229
|
+
node.editor.placeholderString = String(p.placeholder ?? '')
|
|
230
|
+
node.editor.editable = !p.readonly && !p.disabled
|
|
231
|
+
node.editor.enabled = !p.disabled
|
|
232
|
+
node.editor.accessibilityIdentifier = identifier
|
|
233
|
+
node.editor.accessibilityLabel = String(p.label ?? '')
|
|
234
|
+
}
|
|
235
|
+
if (['button', 'link', 'card'].includes(node.kind)) {
|
|
236
|
+
view.title =
|
|
237
|
+
node.kind === 'card'
|
|
238
|
+
? ''
|
|
239
|
+
: String(p.loading ? (p.loadingText ?? 'Loading…') : (p.text ?? text(node)))
|
|
240
|
+
view.enabled = !p.disabled && !p.loading
|
|
241
|
+
view.keyEquivalent = p.shortcut === 'mod+s' ? 's' : ''
|
|
242
|
+
if (node.kind === 'card') {
|
|
243
|
+
setBackground(node.content, theme.colors.surface)
|
|
244
|
+
node.content.layer.cornerRadius = 10
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
if (node.kind === 'reveal') {
|
|
248
|
+
const shown = p.show !== false
|
|
249
|
+
if (node.shown !== shown) {
|
|
250
|
+
node.motion?.cancel()
|
|
251
|
+
node.shown = shown
|
|
252
|
+
view.hidden = !shown
|
|
253
|
+
node.pendingReveal = shown
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
function attach(node, parent) {
|
|
258
|
+
if (!node.native) return
|
|
259
|
+
const host = parent.content
|
|
260
|
+
if (host && node.native.superview !== host) host.addSubview(node.native)
|
|
261
|
+
}
|
|
262
|
+
function detach(node) {
|
|
263
|
+
node.native?.removeFromSuperview()
|
|
264
|
+
nodes.delete(node)
|
|
265
|
+
}
|
|
266
|
+
function layoutNode(node, x, y, width, viewport = 0) {
|
|
267
|
+
if (!node.native) return 0
|
|
268
|
+
if (node.kind === 'reveal' && !node.shown) {
|
|
269
|
+
node.native.frame = rect(x, y, width, 0)
|
|
270
|
+
return 0
|
|
271
|
+
}
|
|
272
|
+
const p = node.props
|
|
273
|
+
let height = 0
|
|
274
|
+
if (node.kind === 'text') {
|
|
275
|
+
height = Math.ceil(node.native.cell.cellSizeForBounds(rect(0, 0, width, 10000)).height) + 2
|
|
276
|
+
} else if (node.kind === 'input') {
|
|
277
|
+
const label = p.label ? 20 : 0
|
|
278
|
+
node.label.frame = rect(0, 0, width, label)
|
|
279
|
+
node.editor.frame = rect(0, label + 4, width, 28)
|
|
280
|
+
height = label + 36
|
|
281
|
+
} else if (node.kind === 'button' || node.kind === 'link') height = 34
|
|
282
|
+
else {
|
|
283
|
+
const pad = tokens(p.padding ?? (node.kind === 'card' ? 'md' : 'none'))
|
|
284
|
+
const gap = tokens(p.gap)
|
|
285
|
+
const children = node.children.filter(
|
|
286
|
+
(child) => child.native && !(child.kind === 'reveal' && !child.shown),
|
|
287
|
+
)
|
|
288
|
+
const columns =
|
|
289
|
+
node.kind === 'grid'
|
|
290
|
+
? Math.max(
|
|
291
|
+
1,
|
|
292
|
+
Math.floor((width - pad * 2 + gap) / (Number(p.minColumnWidth ?? 240) + gap)),
|
|
293
|
+
)
|
|
294
|
+
: node.kind === 'row'
|
|
295
|
+
? Math.max(1, children.length)
|
|
296
|
+
: 1
|
|
297
|
+
const cellWidth = (width - pad * 2 - gap * (columns - 1)) / columns
|
|
298
|
+
let top = pad
|
|
299
|
+
for (let index = 0; index < children.length; index += columns) {
|
|
300
|
+
let rowHeight = 0
|
|
301
|
+
for (let col = 0; col < columns && index + col < children.length; col++)
|
|
302
|
+
rowHeight = Math.max(
|
|
303
|
+
rowHeight,
|
|
304
|
+
layoutNode(
|
|
305
|
+
children[index + col],
|
|
306
|
+
pad + col * (cellWidth + gap),
|
|
307
|
+
top,
|
|
308
|
+
cellWidth,
|
|
309
|
+
viewport,
|
|
310
|
+
),
|
|
311
|
+
)
|
|
312
|
+
top += rowHeight + gap
|
|
313
|
+
}
|
|
314
|
+
height = top + pad - (children.length ? gap : 0)
|
|
315
|
+
if (node.kind === 'screen') {
|
|
316
|
+
node.content.frame = rect(0, 0, width, Math.max(viewport, height))
|
|
317
|
+
height = viewport
|
|
318
|
+
} else if (node.kind === 'card') node.content.frame = rect(4, 4, width - 8, height)
|
|
319
|
+
}
|
|
320
|
+
if (node.kind === 'root') height = viewport
|
|
321
|
+
node.native.frame = rect(x, y, width, Math.max(height, 0))
|
|
322
|
+
return height
|
|
323
|
+
}
|
|
324
|
+
function layout() {
|
|
325
|
+
if (scheduled || closed) return
|
|
326
|
+
scheduled = true
|
|
327
|
+
queueMicrotask(() => {
|
|
328
|
+
scheduled = false
|
|
329
|
+
if (closed) return
|
|
330
|
+
const { width, height } = window.contentView.bounds.size
|
|
331
|
+
layoutNode(root, 0, 0, width, height)
|
|
332
|
+
for (const node of nodes) {
|
|
333
|
+
if (node.pendingReveal && node.native.window) {
|
|
334
|
+
node.pendingReveal = false
|
|
335
|
+
node.motion = opacityMotion(node.native, 0, 1, reduced())
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
window.recalculateKeyViewLoop()
|
|
339
|
+
})
|
|
340
|
+
}
|
|
341
|
+
function setTheme(dark) {
|
|
342
|
+
theme = dark ? midnight : mavis
|
|
343
|
+
window.appearance = NSAppearance.appearanceNamed(
|
|
344
|
+
dark ? 'NSAppearanceNameDarkAqua' : 'NSAppearanceNameAqua',
|
|
345
|
+
)
|
|
346
|
+
window.backgroundColor = nativeColor(theme.colors.background)
|
|
347
|
+
for (const node of nodes) update(node)
|
|
348
|
+
layout()
|
|
349
|
+
}
|
|
350
|
+
function stop() {
|
|
351
|
+
if (closed) return
|
|
352
|
+
closed = true
|
|
353
|
+
clearTimeout(pumpTimer)
|
|
354
|
+
for (const sheet of sheets) window.endSheetReturnCode(sheet.window, NSModalResponseCancel)
|
|
355
|
+
sheets.clear()
|
|
356
|
+
NSWorkspace.sharedWorkspace.notificationCenter.removeObserver(accessibilityObserver)
|
|
357
|
+
for (const node of nodes) node.dispose?.()
|
|
358
|
+
nodes.clear()
|
|
359
|
+
window.delegate = null
|
|
360
|
+
delegate.resize = delegate.close = null
|
|
361
|
+
for (const target of actions) target.callback = null
|
|
362
|
+
app.mainMenu = null
|
|
363
|
+
}
|
|
364
|
+
const delegate = MavisAppKitWindowDelegate.new()
|
|
365
|
+
delegate.resize = layout
|
|
366
|
+
delegate.close = () => {
|
|
367
|
+
onClose()
|
|
368
|
+
stop()
|
|
369
|
+
}
|
|
370
|
+
window.delegate = delegate
|
|
371
|
+
const menu = NSMenu.new()
|
|
372
|
+
function addMenu(name, items) {
|
|
373
|
+
const submenu = NSMenu.alloc().initWithTitle(name)
|
|
374
|
+
for (const [label, selector, key, callback] of items) {
|
|
375
|
+
const item = submenu.addItemWithTitleActionKeyEquivalent(label, selector, key)
|
|
376
|
+
if (callback) actions.push(action(item, callback))
|
|
377
|
+
}
|
|
378
|
+
const item = NSMenuItem.new()
|
|
379
|
+
item.submenu = submenu
|
|
380
|
+
menu.addItem(item)
|
|
381
|
+
}
|
|
382
|
+
addMenu('Mavis', [['Quit Mavis', 'activate:', 'q', () => window.performClose(null)]])
|
|
383
|
+
addMenu('Edit', [
|
|
384
|
+
['Undo', 'undo:', 'z'],
|
|
385
|
+
['Redo', 'redo:', 'Z'],
|
|
386
|
+
['Cut', 'cut:', 'x'],
|
|
387
|
+
['Copy', 'copy:', 'c'],
|
|
388
|
+
['Paste', 'paste:', 'v'],
|
|
389
|
+
['Select All', 'selectAll:', 'a'],
|
|
390
|
+
])
|
|
391
|
+
addMenu('View', [['Toggle theme', 'activate:', 't', () => setTheme(theme === mavis)]])
|
|
392
|
+
function openInfoSheet() {
|
|
393
|
+
const sheet = NSAlert.new()
|
|
394
|
+
sheet.messageText = 'Community directory'
|
|
395
|
+
sheet.informativeText =
|
|
396
|
+
'Find a place to learn, create or meet your neighbours. Changes are saved on this Mac.'
|
|
397
|
+
sheet.addButtonWithTitle('Done')
|
|
398
|
+
sheet.addButtonWithTitle('Cancel')
|
|
399
|
+
sheets.add(sheet)
|
|
400
|
+
sheet.beginSheetModalForWindowCompletionHandler(window, () => sheets.delete(sheet))
|
|
401
|
+
return sheet
|
|
402
|
+
}
|
|
403
|
+
addMenu('Help', [['About Community directory', 'activate:', '', openInfoSheet]])
|
|
404
|
+
app.mainMenu = menu
|
|
405
|
+
setTheme(false)
|
|
406
|
+
function show() {
|
|
407
|
+
app.finishLaunching()
|
|
408
|
+
window.center()
|
|
409
|
+
window.makeKeyAndOrderFront(null)
|
|
410
|
+
app.activateIgnoringOtherApps(true)
|
|
411
|
+
const pump = () => {
|
|
412
|
+
if (closed) return
|
|
413
|
+
for (let i = 0; i < 64; i++) {
|
|
414
|
+
const event = app.nextEventMatchingMaskUntilDateInModeDequeue(
|
|
415
|
+
NSEventMask.Any,
|
|
416
|
+
null,
|
|
417
|
+
'kCFRunLoopDefaultMode',
|
|
418
|
+
true,
|
|
419
|
+
)
|
|
420
|
+
if (!event) break
|
|
421
|
+
app.sendEvent(event)
|
|
422
|
+
}
|
|
423
|
+
app.updateWindows()
|
|
424
|
+
pumpTimer = setTimeout(pump, 4)
|
|
425
|
+
}
|
|
426
|
+
pump()
|
|
427
|
+
layout()
|
|
428
|
+
}
|
|
429
|
+
function setReducedMotion(value) {
|
|
430
|
+
reducedOverride = value
|
|
431
|
+
if (reduced())
|
|
432
|
+
for (const node of nodes)
|
|
433
|
+
if (node.kind === 'reveal' && node.shown) {
|
|
434
|
+
node.motion?.cancel()
|
|
435
|
+
node.motion = opacityMotion(node.native, 1, 1, true)
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
const accessibilityObserver =
|
|
439
|
+
NSWorkspace.sharedWorkspace.notificationCenter.addObserverForNameObjectQueueUsingBlock(
|
|
440
|
+
'NSWorkspaceAccessibilityDisplayOptionsDidChangeNotification',
|
|
441
|
+
null,
|
|
442
|
+
null,
|
|
443
|
+
() => setReducedMotion(reducedOverride),
|
|
444
|
+
)
|
|
445
|
+
return {
|
|
446
|
+
root,
|
|
447
|
+
window,
|
|
448
|
+
nodes,
|
|
449
|
+
sheets,
|
|
450
|
+
create,
|
|
451
|
+
update,
|
|
452
|
+
attach,
|
|
453
|
+
detach,
|
|
454
|
+
layout,
|
|
455
|
+
show,
|
|
456
|
+
close() {
|
|
457
|
+
window.performClose(null)
|
|
458
|
+
},
|
|
459
|
+
stop,
|
|
460
|
+
setTheme,
|
|
461
|
+
addMenu,
|
|
462
|
+
openInfoSheet,
|
|
463
|
+
setReducedMotion,
|
|
464
|
+
get closed() {
|
|
465
|
+
return closed
|
|
466
|
+
},
|
|
467
|
+
}
|
|
468
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { createTrack, instantTrack } from '#jolt-track'
|
|
2
|
+
import { resolveTransition } from '#jolt-transition'
|
|
3
|
+
|
|
4
|
+
/** Finite opacity only. Jolt samples the curve; Core Animation owns every frame. */
|
|
5
|
+
export function opacityMotion(view, from, to, reduced, completed = () => {}) {
|
|
6
|
+
const track = reduced
|
|
7
|
+
? instantTrack('opacity', to)
|
|
8
|
+
: createTrack(
|
|
9
|
+
'opacity',
|
|
10
|
+
[from, to],
|
|
11
|
+
resolveTransition({ duration: 240, ease: 'easeOut' }, 'opacity', 2),
|
|
12
|
+
0,
|
|
13
|
+
{ timeScale: 1, reducedMotion: false },
|
|
14
|
+
)
|
|
15
|
+
const layer = view.layer
|
|
16
|
+
const key = 'mavis:jolt:opacity'
|
|
17
|
+
let active = true
|
|
18
|
+
const finish = (finished) => {
|
|
19
|
+
if (!active) return
|
|
20
|
+
active = false
|
|
21
|
+
completed(finished)
|
|
22
|
+
}
|
|
23
|
+
CATransaction.begin()
|
|
24
|
+
CATransaction.setDisableActions(true)
|
|
25
|
+
layer.opacity = track.to
|
|
26
|
+
if (track.duration > 0) {
|
|
27
|
+
const animation = CAKeyframeAnimation.animationWithKeyPath('opacity')
|
|
28
|
+
animation.values = NSArray.arrayWithArray([...track.values])
|
|
29
|
+
animation.keyTimes = NSArray.arrayWithArray([...track.times])
|
|
30
|
+
animation.duration = track.duration / 1000
|
|
31
|
+
CATransaction.setCompletionBlock(() => finish(true))
|
|
32
|
+
layer.addAnimationForKey(animation, key)
|
|
33
|
+
}
|
|
34
|
+
CATransaction.commit()
|
|
35
|
+
if (track.duration === 0) finish(true)
|
|
36
|
+
return {
|
|
37
|
+
get active() {
|
|
38
|
+
return active
|
|
39
|
+
},
|
|
40
|
+
cancel() {
|
|
41
|
+
if (!active) return
|
|
42
|
+
const value = layer.presentationLayer?.opacity ?? layer.opacity
|
|
43
|
+
finish(false)
|
|
44
|
+
CATransaction.begin()
|
|
45
|
+
CATransaction.setDisableActions(true)
|
|
46
|
+
layer.opacity = value
|
|
47
|
+
layer.removeAnimationForKey(key)
|
|
48
|
+
CATransaction.commit()
|
|
49
|
+
},
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref } from 'vue'
|
|
3
|
+
import { MScreen, MColumn, MRow, MText, MInput, MButton, MReveal, MAlert } from '#mavis'
|
|
4
|
+
import { useProjectService } from './services'
|
|
5
|
+
const service = useProjectService()
|
|
6
|
+
const name = ref('A new beginning'),
|
|
7
|
+
count = ref(0),
|
|
8
|
+
saving = ref(false),
|
|
9
|
+
saved = ref(false),
|
|
10
|
+
error = ref('')
|
|
11
|
+
async function save() {
|
|
12
|
+
if (saving.value || !name.value.trim()) return
|
|
13
|
+
saving.value = true
|
|
14
|
+
error.value = ''
|
|
15
|
+
saved.value = false
|
|
16
|
+
try {
|
|
17
|
+
await service.save(name.value.trim())
|
|
18
|
+
saved.value = true
|
|
19
|
+
} catch {
|
|
20
|
+
error.value = 'Could not save. Your draft is still here; try again.'
|
|
21
|
+
} finally {
|
|
22
|
+
saving.value = false
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
</script>
|
|
26
|
+
<template>
|
|
27
|
+
<MScreen scroll>
|
|
28
|
+
<MColumn padding="lg" gap="lg">
|
|
29
|
+
<MText variant="title">__MAVIS_NAME__</MText>
|
|
30
|
+
<MText tone="muted">One Vue screen, native controls on every selected platform.</MText>
|
|
31
|
+
<MInput
|
|
32
|
+
id="project-name"
|
|
33
|
+
v-model="name"
|
|
34
|
+
label="Project name"
|
|
35
|
+
@submit="save"
|
|
36
|
+
@update:modelValue="saved = false"
|
|
37
|
+
/>
|
|
38
|
+
<MText id="greeting">{{ name }}</MText>
|
|
39
|
+
<MRow gap="md">
|
|
40
|
+
<MButton id="increment" :text="`Count ${count}`" @click="count++" />
|
|
41
|
+
<MButton
|
|
42
|
+
id="save-project"
|
|
43
|
+
text="Save project"
|
|
44
|
+
:disabled="!name.trim()"
|
|
45
|
+
:loading="saving"
|
|
46
|
+
loadingText="Saving…"
|
|
47
|
+
@click="save"
|
|
48
|
+
/>
|
|
49
|
+
</MRow>
|
|
50
|
+
<MAlert v-if="error" title="Save failed" :description="error" />
|
|
51
|
+
<MReveal :show="saved"
|
|
52
|
+
><MText id="saved" tone="success">Your project is saved.</MText></MReveal
|
|
53
|
+
>
|
|
54
|
+
</MColumn>
|
|
55
|
+
</MScreen>
|
|
56
|
+
</template>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createHost } from '#desktop-host'
|
|
2
|
+
import { desktopRenderer } from './renderer'
|
|
3
|
+
import { persistence, storageFile } from './storage'
|
|
4
|
+
import Welcome from '#shared-ui/Welcome.vue'
|
|
5
|
+
import { projectServiceKey } from '#shared-ui/services'
|
|
6
|
+
let application: ReturnType<ReturnType<typeof desktopRenderer>['createApp']>
|
|
7
|
+
const host = createHost({
|
|
8
|
+
title: '__MAVIS_NAME__',
|
|
9
|
+
onClose() {
|
|
10
|
+
application?.unmount()
|
|
11
|
+
},
|
|
12
|
+
})
|
|
13
|
+
const storage = persistence(() => host.closed)
|
|
14
|
+
application = desktopRenderer(host).createApp(Welcome)
|
|
15
|
+
application.provide(projectServiceKey, { save: (name: string) => storage.write(name) })
|
|
16
|
+
host.setTheme('__MAVIS_THEME__' === 'midnight')
|
|
17
|
+
application.mount(host.root)
|
|
18
|
+
host.show()
|
|
19
|
+
// A local acceptance hook is loaded only when explicitly supplied by the developer.
|
|
20
|
+
if (process.env.MAVIS_DESKTOP_CHECK) {
|
|
21
|
+
const { pathToFileURL } = await import('node:url')
|
|
22
|
+
const { default: check } = await import(pathToFileURL(process.env.MAVIS_DESKTOP_CHECK).href)
|
|
23
|
+
await check({ host, application, storageFile })
|
|
24
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright OpenJS Foundation and other contributors, https://openjsf.org
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process'
|
|
2
|
+
import { dirname, resolve } from 'node:path'
|
|
3
|
+
import { fileURLToPath } from 'node:url'
|
|
4
|
+
import { prepareWindowsHost } from './prepare-host.mjs'
|
|
5
|
+
const here = dirname(fileURLToPath(import.meta.url))
|
|
6
|
+
const executable = prepareWindowsHost(resolve(here, '.mavis/runtime/node.exe'))
|
|
7
|
+
const child = spawn(executable, [resolve(here, 'dist/main.mjs'), ...process.argv.slice(2)], {
|
|
8
|
+
stdio: 'inherit',
|
|
9
|
+
})
|
|
10
|
+
child.on('error', (error) => {
|
|
11
|
+
console.error(error.message)
|
|
12
|
+
process.exitCode = 1
|
|
13
|
+
})
|
|
14
|
+
child.on('exit', (code) => {
|
|
15
|
+
process.exitCode = code ?? 1
|
|
16
|
+
})
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { cpSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
2
|
+
import { createRequire } from 'node:module'
|
|
3
|
+
import { dirname, join, resolve } from 'node:path'
|
|
4
|
+
import { fileURLToPath } from 'node:url'
|
|
5
|
+
import { prepareWindowsHost } from './prepare-host.mjs'
|
|
6
|
+
const here = dirname(fileURLToPath(import.meta.url))
|
|
7
|
+
const require = createRequire(import.meta.url)
|
|
8
|
+
const output = resolve(here, `artifacts/__MAVIS_NAME__-win32-${process.arch}`)
|
|
9
|
+
if (process.platform !== 'win32') throw new Error('Package the Windows app on Windows.')
|
|
10
|
+
rmSync(output, { recursive: true, force: true })
|
|
11
|
+
mkdirSync(output, { recursive: true })
|
|
12
|
+
prepareWindowsHost(join(output, 'node.exe'))
|
|
13
|
+
cpSync(join(here, 'dist/main.mjs'), join(output, 'dist/main.mjs'))
|
|
14
|
+
const runtime = dirname(require.resolve('@nativescript/windows-napi'))
|
|
15
|
+
cpSync(runtime, join(output, 'node_modules/@nativescript/windows-napi'), { recursive: true })
|
|
16
|
+
writeFileSync(
|
|
17
|
+
join(output, '__MAVIS_NAME__.cmd'),
|
|
18
|
+
'@echo off\r\n"%~dp0node.exe" "%~dp0dist\\main.mjs" %*\r\n',
|
|
19
|
+
)
|
|
20
|
+
const licenses = join(output, 'Licenses')
|
|
21
|
+
mkdirSync(licenses)
|
|
22
|
+
for (const [name, source] of [
|
|
23
|
+
['Mavis', join(here, 'LICENSE')],
|
|
24
|
+
['Vue', join(here, 'node_modules/vue/LICENSE')],
|
|
25
|
+
['VueRouter', join(here, 'node_modules/vue-router/LICENSE')],
|
|
26
|
+
['Jolt', join(here, 'node_modules/@rafaelaugusto/jolt/LICENSE')],
|
|
27
|
+
['NativeScript', join(here, 'NativeScript-LICENSE')],
|
|
28
|
+
])
|
|
29
|
+
cpSync(source, join(licenses, `${name}.txt`))
|
|
30
|
+
const nodeLicense = [
|
|
31
|
+
join(dirname(process.execPath), 'LICENSE'),
|
|
32
|
+
join(dirname(process.execPath), '../LICENSE'),
|
|
33
|
+
].find(existsSync)
|
|
34
|
+
if (!nodeLicense)
|
|
35
|
+
throw new Error(
|
|
36
|
+
'Use the official Node distribution including its LICENSE to package the runtime.',
|
|
37
|
+
)
|
|
38
|
+
cpSync(nodeLicense, join(licenses, 'Node.txt'))
|
|
39
|
+
writeFileSync(
|
|
40
|
+
join(here, 'artifacts/package.json'),
|
|
41
|
+
JSON.stringify(
|
|
42
|
+
{
|
|
43
|
+
directory: output,
|
|
44
|
+
node: process.version,
|
|
45
|
+
arch: process.arch,
|
|
46
|
+
runtime: JSON.parse(readFileSync(join(runtime, 'package.json'), 'utf8')).version,
|
|
47
|
+
minimumWindows: '10 build 18362',
|
|
48
|
+
signing: 'unsigned portable folder; not an installer',
|
|
49
|
+
},
|
|
50
|
+
null,
|
|
51
|
+
2,
|
|
52
|
+
) + '\n',
|
|
53
|
+
)
|
|
54
|
+
console.log(output)
|