-
-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env node | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
|
||
const { context } = require('esbuild'); | ||
const less = require('@arnog/esbuild-plugin-less'); | ||
|
||
// Copy and watch the smoke test file | ||
context({ | ||
entryPoints: [ | ||
'./test/style.css', | ||
'./test/smoke/index.html', | ||
'./test/virtual-keyboard/index.html', | ||
'./test/mathfield-states/index.html', | ||
'./test/prompts/index.html', | ||
'./test/playwright-test-page/index.html', | ||
'./test/playwright-test-page/iframe_test.html', | ||
], | ||
outdir: './dist', | ||
loader: { | ||
'.html': 'copy', | ||
'.css': 'copy', | ||
}, | ||
}).then((ctx) => ctx.watch()); | ||
|
||
// Build and serve the library | ||
context({ | ||
entryPoints: ['./src/mathlive.ts'], | ||
outfile: './dist/mathlive.mjs', | ||
format: 'esm', | ||
bundle: true, | ||
plugins: [less()], | ||
loader: { | ||
'.ts': 'ts', | ||
}, | ||
sourcemap: true, | ||
sourceRoot: '../src', | ||
sourcesContent: false, | ||
}).then((ctx) => | ||
ctx | ||
.serve({ host: '127.0.0.1', port: 9029, servedir: '.' }) | ||
.then(({ host, port }) => { | ||
if (host === '0.0.0.0') host = 'localhost'; | ||
console.log( | ||
` 🚀 Server ready \u001b[1;35m http://${host}:${port}/dist/smoke/\u001b[0m` | ||
); | ||
}) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
export default { | ||
name: 'mathlive-mathfield', | ||
template: '<math-field :id="id"><slot></slot></math-field>', | ||
props: { | ||
id: { | ||
type: String, | ||
default: '', | ||
}, | ||
value: { | ||
type: String, | ||
default: '', | ||
}, | ||
options: { | ||
type: Object, | ||
default: () => ({}), | ||
}, | ||
}, | ||
/* | ||
* To register this component, call: | ||
* ``` | ||
* import * as MathLive from './mathlive.mjs'; | ||
* import MathfieldComponent from './vue-mathlive.mjs'; | ||
* Vue.use(MathfieldComponent, MathLive); | ||
* ``` | ||
* | ||
* The HTML tag for this component is `<mathlive-mathfield>` | ||
* | ||
* @param {object} vue - This module, as returned from an import statement | ||
* @param {object} mathlive - The MathLive module, as returned from an import | ||
* statement | ||
*/ | ||
install(vue, mathlive) { | ||
// When the component is installed (with Vue.use()), the first argument | ||
// should be the component (as received from import) and the second | ||
// should be the MathLive module (also as received from import). | ||
// The MathLive module then gets stashed as a property of the Vue | ||
// object to be accessed later by the component implementation. | ||
// This allows the user of the component to control which version of | ||
// the MathLive module gets used. | ||
|
||
if (vue?.version && +vue.version.split('.')[0] >= 3) { | ||
// Vue >= 3.x | ||
vue.config.globalProperties.$mathlive = mathlive; | ||
} else { | ||
// Vue < 3.x | ||
Object.defineProperty(vue.prototype, '$mathlive', { value: mathlive }); | ||
} | ||
|
||
vue.component('mathlive-mathfield', this); | ||
}, | ||
watch: { | ||
value(newValue) { | ||
// When the `value` prop (from the model) is modified | ||
// update the mathfield to stay in sync, but don't send back content | ||
// change notifications, to avoid infinite loops. | ||
const oldMathfieldValue = this.$el.getValue(); | ||
if (newValue !== oldMathfieldValue) { | ||
this.$el.setValue(newValue, { | ||
silenceNotifications: true, | ||
}); | ||
} | ||
}, | ||
options: { | ||
deep: true, | ||
handler(newValue, oldValue) { | ||
if (JSON.stringify(newValue) !== JSON.stringify(oldValue)) | ||
this.$el.setOptions(newValue); | ||
}, | ||
}, | ||
}, | ||
mounted() { | ||
// A new instance is being created | ||
// Wait until the DOM has been constructed... | ||
// ... then configure the mathfield | ||
this.$nextTick(() => this.$el.setOptions(this.options)); | ||
}, | ||
methods: { | ||
/* | ||
* | ||
* @param {string} selector | ||
*/ | ||
executeCommand(selector) { | ||
this.$el.executeCommand(selector); | ||
}, | ||
/* | ||
* @return {boolean} | ||
*/ | ||
hasFocus() { | ||
return this.$el.hasFocus(); | ||
}, | ||
focus() { | ||
this.$el.focus(); | ||
}, | ||
blur() { | ||
this.$el.blur(); | ||
}, | ||
getValue(format) { | ||
return this.$el.getValue(format); | ||
}, | ||
insert(text, options) { | ||
this.$el.insert(text, options); | ||
}, | ||
select() { | ||
this.$el.select(); | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = 'MOCK_STYLE'; |