@alchymia/canvas 0.0.0-stage → 1.0.1
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 +20 -2
- package/browser.d.ts +19 -0
- package/browser.mjs +84 -0
- package/dist/THIRD-PARTY-NOTICES.txt +2052 -0
- package/dist/drawer.js +2 -0
- package/dist/drawer.js.LICENSE.txt +24 -0
- package/dist/frame.js +2 -0
- package/dist/frame.js.LICENSE.txt +29 -0
- package/package.json +17 -4
- package/vue2.js +1 -0
package/README.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Alchymia Canvas
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Butla and Groom use this package for the Canvas drawer, board and linked-document editors. The host application owns authentication, permissions and persistence.
|
|
4
|
+
|
|
5
|
+
## Butla
|
|
6
|
+
|
|
7
|
+
Import the Vue 2 drawer from `@alchymia/canvas/vue2`. The existing Butla entry point forwards its props, events and component methods through that export.
|
|
8
|
+
|
|
9
|
+
## Groom
|
|
10
|
+
|
|
11
|
+
Import `mountCanvas` from `@alchymia/canvas/browser`. Pass a DOM element, drawer props, the authorised Canvas API adapter and the original drawer event handlers. The package runs Vue 2 inside the editor frame and loads the same shared styles as Butla. The host can use Vue 3.
|
|
12
|
+
|
|
13
|
+
Set `host.$auth.user.config.ai.name` to the active workspace's assistant name. The toolbar, task menus and linked documents read this same value. Personal Butla uses the signed-in user's assistant name and defaults to Butla.
|
|
14
|
+
|
|
15
|
+
When a workspace task opens Ask, the `workspace-ask` event includes its `canvasId`, `taskId` and draft `prompt`. For linked work, `canvasId` identifies the linked document.
|
|
16
|
+
|
|
17
|
+
Await `ready` before using the editor. Await `flushForNavigation()` before changing records or leaving the route. A false result keeps the editor open for recovery. Call `destroy()` when the host unmounts.
|
|
18
|
+
|
|
19
|
+
## Building a release
|
|
20
|
+
|
|
21
|
+
From the Butla interactive checkout, install the locked dependencies and run `npm run build:canvas`. The build reads the original editor, its shared components and the application's stylesheet configuration. Run `npm pack` in `packages/canvas` and test that archive in both applications. Publish the verified archive to the public npm registry and pin the same version in both application manifests.
|
package/browser.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface CanvasProps {
|
|
2
|
+
purchase_id: string
|
|
3
|
+
visible: boolean
|
|
4
|
+
title?: string
|
|
5
|
+
kind?: string
|
|
6
|
+
content?: string
|
|
7
|
+
workspace_id?: string
|
|
8
|
+
}
|
|
9
|
+
export interface CanvasMount {
|
|
10
|
+
ready: Promise<void>
|
|
11
|
+
update(props: Partial<CanvasProps>): void
|
|
12
|
+
flushForNavigation(): Promise<boolean>
|
|
13
|
+
destroy(): void
|
|
14
|
+
}
|
|
15
|
+
export function mountCanvas(element: HTMLElement, options: {
|
|
16
|
+
props: CanvasProps
|
|
17
|
+
host: Record<string, unknown>
|
|
18
|
+
on?: Record<string, (value?: unknown) => void>
|
|
19
|
+
}): CanvasMount
|
package/browser.mjs
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// Keep the editor, its selection, drag events and Element UI portals in one document.
|
|
2
|
+
const frameURL = new URL('./dist/frame.js', import.meta.url)
|
|
3
|
+
const drawerURL = new URL('./dist/drawer.js', import.meta.url)
|
|
4
|
+
|
|
5
|
+
function loadScript(doc, url) {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
const script = doc.createElement('script')
|
|
8
|
+
script.charset = 'utf-8'
|
|
9
|
+
script.onload = resolve
|
|
10
|
+
script.onerror = () => reject(new Error('Could not load the Canvas editor.'))
|
|
11
|
+
script.src = url.href
|
|
12
|
+
doc.head.appendChild(script)
|
|
13
|
+
})
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function mountCanvas(element, { props, host, on = {} }) {
|
|
17
|
+
const owner = element.ownerDocument
|
|
18
|
+
const previousFocus = owner.activeElement
|
|
19
|
+
const frame = owner.createElement('iframe')
|
|
20
|
+
frame.title = 'Canvas'
|
|
21
|
+
frame.style.cssText = 'position:fixed;inset:0;border:0;width:100%;height:100%;z-index:2100;'
|
|
22
|
+
let currentProps = { ...props }
|
|
23
|
+
frame.hidden = currentProps.visible === false
|
|
24
|
+
element.appendChild(frame)
|
|
25
|
+
const doc = frame.contentDocument
|
|
26
|
+
// about:blank starts in quirks mode in some browsers. Use the same standards mode as Nuxt.
|
|
27
|
+
doc.open()
|
|
28
|
+
doc.write('<!doctype html><html><head><meta charset="utf-8"></head><body></body></html>')
|
|
29
|
+
doc.close()
|
|
30
|
+
const realm = frame.contentWindow
|
|
31
|
+
doc.documentElement.lang = owner.documentElement.lang || 'en'
|
|
32
|
+
const syncTheme = () => {
|
|
33
|
+
const theme = owner.documentElement.classList.contains('dark') ? 'dark'
|
|
34
|
+
: owner.body.getAttribute('theme') || owner.documentElement.dataset.theme || 'light'
|
|
35
|
+
doc.body.setAttribute('theme', theme)
|
|
36
|
+
doc.documentElement.dataset.theme = theme
|
|
37
|
+
doc.documentElement.classList.toggle('dark', theme === 'dark')
|
|
38
|
+
}
|
|
39
|
+
syncTheme()
|
|
40
|
+
const observer = new MutationObserver(syncTheme)
|
|
41
|
+
for (const node of [owner.body, owner.documentElement]) {
|
|
42
|
+
observer.observe(node, { attributes: true, attributeFilter: ['theme', 'data-theme', 'class'] })
|
|
43
|
+
}
|
|
44
|
+
const root = doc.createElement('div')
|
|
45
|
+
doc.body.appendChild(root)
|
|
46
|
+
let mounted, destroyed = false, cancelLoad
|
|
47
|
+
const canceled = new Promise((_, reject) => { cancelLoad = reject })
|
|
48
|
+
const ready = Promise.race([canceled, (async () => {
|
|
49
|
+
await loadScript(doc, frameURL)
|
|
50
|
+
if (destroyed) return
|
|
51
|
+
await loadScript(doc, drawerURL)
|
|
52
|
+
if (destroyed) return
|
|
53
|
+
mounted = realm.AlchymiaCanvasFrame.mount(root, realm.AlchymiaCanvasDrawer.default, {
|
|
54
|
+
props: currentProps, host, on,
|
|
55
|
+
})
|
|
56
|
+
await realm.Vue.nextTick()
|
|
57
|
+
})()])
|
|
58
|
+
function destroy() {
|
|
59
|
+
if (destroyed) return
|
|
60
|
+
destroyed = true
|
|
61
|
+
cancelLoad(new DOMException('Canvas was closed.', 'AbortError'))
|
|
62
|
+
observer.disconnect()
|
|
63
|
+
const restoreFocus = owner.activeElement === frame
|
|
64
|
+
try { mounted?.destroy() } finally {
|
|
65
|
+
frame.remove()
|
|
66
|
+
if (restoreFocus && previousFocus?.isConnected) previousFocus.focus()
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
ready.catch(destroy)
|
|
70
|
+
return {
|
|
71
|
+
ready,
|
|
72
|
+
update(next) {
|
|
73
|
+
if (destroyed) return
|
|
74
|
+
currentProps = { ...currentProps, ...next }
|
|
75
|
+
frame.hidden = currentProps.visible === false
|
|
76
|
+
mounted?.update(next)
|
|
77
|
+
},
|
|
78
|
+
async flushForNavigation() {
|
|
79
|
+
await ready
|
|
80
|
+
return !destroyed && mounted.flushForNavigation()
|
|
81
|
+
},
|
|
82
|
+
destroy,
|
|
83
|
+
}
|
|
84
|
+
}
|