Skip to content

Commit c7545a7

Browse files
authored
Merge pull request SolidOS#171 from solid/migrate-media
Migrate media
2 parents 8009dd8 + 17b895e commit c7545a7

16 files changed

Lines changed: 188 additions & 188 deletions

src/chat/bookmarks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const UI = {
1111
authn: require('../authn/authn'),
1212
icons: require('../iconBase'),
1313
ns: require('../ns'),
14-
media: require('../media-capture'),
14+
media: require('../media/media-capture'),
1515
pad: require('../pad'),
1616
rdf: require('rdflib'),
1717
store: require('../logic').solidLogicSingleton.store,

src/chat/infinite.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const UI = {
1717
authn: require('../authn/authn'),
1818
icons: require('../iconBase'),
1919
ns: require('../ns'),
20-
media: require('../media-capture'),
20+
media: require('../media/media-capture'),
2121
pad: require('../pad'),
2222
rdf: require('rdflib'),
2323
store: require('../logic').solidLogicSingleton.store,

src/chat/message.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const UI = {
1212
authn: require('../authn/authn'),
1313
icons: require('../iconBase'),
1414
ns: require('../ns'),
15-
media: require('../media-capture'),
15+
media: require('../media/media-capture'),
1616
pad: require('../pad'),
1717
rdf: require('rdflib'),
1818
store: require('../logic').solidLogicSingleton.store,

src/chat/messageTools.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const UI = {
1414
authn: require('../authn/authn'),
1515
icons: require('../iconBase'),
1616
ns: require('../ns'),
17-
media: require('../media-capture'),
17+
media: require('../media/media-capture'),
1818
pad: require('../pad'),
1919
rdf: require('rdflib'),
2020
store: require('../logic').solidLogicSingleton.store,

src/create.js renamed to src/create/create.ts

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,18 @@
77

88
// const UI = require('solid-ui')
99

10-
import * as debug from './debug'
10+
import * as debug from '../debug'
1111

12-
const UI = {
13-
authn: require('./authn/authn'),
14-
icons: require('./iconBase'),
15-
ns: require('./ns'),
16-
store: require('./logic').solidLogicSingleton.store,
17-
style: require('./style'),
18-
utils: require('./utils'),
19-
widgets: require('./widgets')
20-
}
21-
22-
const kb = UI.store
12+
import icons from '../iconBase'
13+
import utils from '../utils'
14+
import widgets from '../widgets'
15+
import { solidLogicSingleton } from '../logic'
16+
import ns from '../ns'
17+
import { logInLoadProfile, selectWorkspace } from '../authn/authn'
18+
import { DataBrowserContext, NewPaneOptions, PaneDefinition } from 'pane-registry'
19+
import { CreateContext, NewAppInstanceOptions } from './types'
2320

24-
module.exports = {
25-
newThingUI
26-
}
21+
const kb = solidLogicSingleton.store
2722

2823
/* newThingUI -- return UI for user to select a new object, folder, etc
2924
**
@@ -32,8 +27,11 @@ module.exports = {
3227
** (suppresses asking for a full URI or workspace)
3328
**
3429
*/
35-
function newThingUI (createContext, dataBrowserContext, thePanes) {
36-
if (!thePanes) throw new Error('@@ newThingUI: update API') // phase out
30+
export function newThingUI (
31+
createContext: CreateContext,
32+
dataBrowserContext: DataBrowserContext,
33+
thePanes: Array<PaneDefinition>
34+
): void {
3735
const dom = createContext.dom
3836
const div = createContext.div
3937
if (createContext.me && !createContext.me.uri) {
@@ -45,7 +43,7 @@ function newThingUI (createContext, dataBrowserContext, thePanes) {
4543
let visible = false // the inividual tools tools
4644
// noun_272948.svg = black star
4745
// noun_34653_green.svg = green plus
48-
star.setAttribute('src', UI.icons.iconBase + 'noun_34653_green.svg')
46+
star.setAttribute('src', icons.iconBase + 'noun_34653_green.svg')
4947
star.setAttribute('style', iconStyle)
5048
star.setAttribute('title', 'Add another tool')
5149

@@ -71,7 +69,7 @@ function newThingUI (createContext, dataBrowserContext, thePanes) {
7169
icon.setAttribute('style', iconStyle + 'background-color: yellow;')
7270
}
7371

74-
function selectNewTool (_event) {
72+
function selectNewTool (_event?) {
7573
visible = !visible
7674
star.setAttribute(
7775
'style',
@@ -82,28 +80,23 @@ function newThingUI (createContext, dataBrowserContext, thePanes) {
8280

8381
star.addEventListener('click', selectNewTool)
8482

85-
function makeNewAppInstance (options) {
83+
function makeNewAppInstance (options: NewAppInstanceOptions) {
8684
return new Promise(function (resolve, reject) {
8785
let selectUI // , selectUIParent
8886
function callbackWS (ws, newBase) {
89-
UI.authn.logInLoadProfile(createContext).then(
87+
logInLoadProfile(createContext).then(
9088
_context => {
91-
const newPaneOptions = {
89+
const newPaneOptions: NewPaneOptions = Object.assign({
9290
newBase: newBase,
9391
workspace: ws
94-
}
92+
}, options)
9593
for (const opt in options) {
9694
// get div, dom, me, folder, pane, refreshTable
9795
newPaneOptions[opt] = options[opt]
9896
}
99-
debug.log(
100-
'newThingUI: Minting new ' +
101-
newPaneOptions.pane.name +
102-
' at ' +
103-
newPaneOptions.newBase
104-
)
97+
debug.log(`newThingUI: Minting new ${newPaneOptions.pane.name} at ${newPaneOptions.newBase}`)
10598
options.pane
106-
.mintNew(dataBrowserContext, newPaneOptions)
99+
.mintNew!(dataBrowserContext, newPaneOptions)
107100
.then(function (newPaneOptions) {
108101
if (!newPaneOptions || !newPaneOptions.newInstance) {
109102
throw new Error('Cannot mint new - missing newInstance')
@@ -117,21 +110,23 @@ function newThingUI (createContext, dataBrowserContext, thePanes) {
117110
if (isPackage) {
118111
kb.add(
119112
newPaneOptions.folder,
120-
UI.ns.ldp('contains'),
113+
ns.ldp('contains'),
121114
kb.sym(newPaneOptions.newBase),
122115
newPaneOptions.folder.doc()
123116
)
124117
} else {
125118
// single file
126119
kb.add(
127120
newPaneOptions.folder,
128-
UI.ns.ldp('contains'),
121+
ns.ldp('contains'),
129122
newPaneOptions.newInstance,
130123
newPaneOptions.folder.doc()
131124
) // Ping the patch system?
132125
}
126+
// @ts-ignore @@ TODO check whether refresh can exist here. Either fix type or remove unreachable code
133127
if (newPaneOptions.refreshTarget && newPaneOptions.refreshTarget.refresh) {
134-
newPaneOptions.refreshTarget.refresh() // Refresh the cntaining display
128+
// @@ TODO Remove the need to cast as any
129+
;(newPaneOptions.refreshTarget as any).refresh() // Refresh the containing display
135130
}
136131
// selectUI.parentNode.removeChild(selectUI) It removes itself
137132
} else {
@@ -168,12 +163,15 @@ function newThingUI (createContext, dataBrowserContext, thePanes) {
168163

169164
const pa = options.pane
170165
// options.appPathSegment = pa.name // was 'edu.mit.solid.pane.'
171-
options.noun = pa.mintClass ? UI.utils.label(pa.mintClass) : pa.name
166+
options.noun = pa.mintClass ? utils.label(pa.mintClass) : pa.name
172167
options.appPathSegment = options.noun.slice(0, 1).toUpperCase() + options.noun.slice(1)
173168

174169
if (!options.folder) {
175170
// No folder given? Ask user for full URI
176-
selectUI = UI.authn.selectWorkspace(dom, options, callbackWS)
171+
selectUI = selectWorkspace(dom, {
172+
noun: options.noun,
173+
appPathSegment: options.appPathSegment
174+
}, callbackWS)
177175
options.div.appendChild(selectUI)
178176
// selectUIParent = options.div
179177
} else {
@@ -182,32 +180,32 @@ function newThingUI (createContext, dataBrowserContext, thePanes) {
182180
// selectUIParent.removeChild(selectUI) itremves itself if cancelled
183181
selectNewTool() // toggle star to plain and menu vanish again
184182
} else {
185-
let uri = options.folder.uri
183+
let uri = options.folder!.uri
186184
if (!uri.endsWith('/')) {
187185
uri = uri + '/'
188186
}
189187
uri = uri + encodeURIComponent(name) + '/'
190188
callbackWS(null, uri)
191189
}
192190
}
193-
UI.widgets
191+
widgets
194192
.askName(
195193
dom,
196-
UI.store,
194+
kb,
197195
options.div,
198-
UI.ns.foaf('name'),
196+
ns.foaf('name'),
199197
null,
200198
options.noun
201199
)
202200
.then(gotName)
203-
// selectUI = getNameForm(dom, UI.store, options.noun, gotName)
201+
// selectUI = getNameForm(dom, kb, options.noun, gotName)
204202
// options.div.appendChild(selectUI)
205203
// selectUIParent = options.div
206204
}
207205
})
208206
} // makeNewAppInstance
209207

210-
const iconArray = []
208+
const iconArray: Array<any> = []
211209
const mintingPanes = Object.values(thePanes).filter(pane => pane.mintNew)
212210
const mintingClassMap = mintingPanes.reduce((classMap, pane) => {
213211
if (pane.mintClass) {
@@ -216,12 +214,13 @@ function newThingUI (createContext, dataBrowserContext, thePanes) {
216214
return classMap
217215
}, {})
218216
mintingPanes.forEach(pane => {
219-
const icon = createContext.div.appendChild(dom.createElement('img'))
217+
// @@ TODO Remove the need to cast to any
218+
const icon: any = createContext.div.appendChild(dom.createElement('img'))
220219
icon.setAttribute('src', pane.icon)
221220
const noun = pane.mintClass
222221
? mintingClassMap[pane.mintClass] > 1
223-
? `${UI.utils.label(pane.mintClass)} (using ${pane.name} pane)`
224-
: UI.utils.label(pane.mintClass)
222+
? `${utils.label(pane.mintClass)} (using ${pane.name} pane)`
223+
: utils.label(pane.mintClass)
225224
: pane.name + ' @@'
226225
icon.setAttribute('title', 'Make new ' + noun)
227226
icon.setAttribute('style', iconStyle + 'display: none;')
@@ -231,7 +230,7 @@ function newThingUI (createContext, dataBrowserContext, thePanes) {
231230
selectTool(icon)
232231
makeNewAppInstance({
233232
event: e,
234-
folder: createContext.folder,
233+
folder: createContext.folder || null,
235234
iconEle: icon,
236235
pane,
237236
noun,
@@ -252,16 +251,16 @@ function newThingUI (createContext, dataBrowserContext, thePanes) {
252251
//
253252
/*
254253
function getNameForm (dom, kb, classLabel, gotNameCallback) {
255-
var form = dom.createElement('div') // form is broken as HTML behaviour can resurface on js error
254+
const form = dom.createElement('div') // form is broken as HTML behaviour can resurface on js error
256255
form.innerHTML = '<p>Name of new ' + classLabel + ':</p>'
257-
var namefield = dom.createElement('input')
256+
const namefield = dom.createElement('input')
258257
namefield.setAttribute('type', 'text')
259258
namefield.setAttribute('size', '30')
260-
namefield.setAttribute('style', UI.style.textInputStyle)
259+
namefield.setAttribute('style', style.textInputStyle)
261260
namefield.setAttribute('maxLength', '2048') // No arbitrary limits
262261
namefield.select() // focus next user input
263262
264-
var gotName = function () {
263+
const gotName = function () {
265264
namefield.setAttribute('class', 'pendingedit')
266265
namefield.disabled = true
267266
continueButton.disabled = true
@@ -278,13 +277,13 @@ function getNameForm (dom, kb, classLabel, gotNameCallback) {
278277
279278
form.appendChild(dom.createElement('br'))
280279
281-
var cancel = form.appendChild(UI.widgets.cancelButton(dom))
280+
const cancel = form.appendChild(widgets.cancelButton(dom))
282281
cancel.addEventListener('click', function (e) {
283282
form.parentNode.removeChild(form)
284283
gotNameCallback(false)
285284
}, false)
286285
287-
var continueButton = form.appendChild(UI.widgets.continueButton(dom))
286+
const continueButton = form.appendChild(widgets.continueButton(dom))
288287
continueButton.addEventListener('click', function (e) {
289288
gotName()
290289
}, false)

src/create/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {
2+
newThingUI
3+
} from './create'
4+
5+
export const create = {
6+
newThingUI
7+
}

src/create/types.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { NamedNode } from 'rdflib'
2+
import { PaneDefinition } from 'pane-registry'
3+
4+
export type CreateContext = {
5+
div: HTMLElement
6+
dom: HTMLDocument
7+
folder?: NamedNode
8+
me: NamedNode
9+
refreshTarget?: HTMLTableElement
10+
statusArea: HTMLElement
11+
}
12+
13+
export interface NewAppInstanceOptions {
14+
appPathSegment?: string
15+
event: any
16+
folder: NamedNode | null
17+
iconEle: HTMLImageElement
18+
pane: PaneDefinition
19+
noun: string
20+
noIndexHTML: boolean
21+
div: HTMLElement,
22+
me: NamedNode,
23+
dom: HTMLDocument,
24+
refreshTarget?: HTMLTableElement
25+
}

src/index.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,12 @@ import * as rdf from 'rdflib' // pull in first avoid cross-refs
4242
import ns from './ns'
4343
import { acl, aclControl } from './acl/index'
4444
import { authn } from './authn/index'
45-
// @ts-ignore
46-
import create from './create'
45+
import { create } from './create/index'
4746
// @ts-ignore
4847
import icons from './iconBase'
4948
import * as log from './log'
50-
// @ts-ignore
51-
import matrix from './matrix'
52-
// @ts-ignore
53-
import media from './media-capture'
49+
import { matrix } from './matrix/index'
50+
import { media } from './media/index'
5451
// @ts-ignore
5552
import messageArea from './messageArea'
5653
// @ts-ignore

src/matrix/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {
2+
matrixForQuery
3+
} from './matrix'
4+
5+
export const matrix = {
6+
matrixForQuery
7+
}

0 commit comments

Comments
 (0)