Skip to content

Commit

Permalink
Added some js files back
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashp116 committed Jul 17, 2024
1 parent 8c0afc6 commit 7b3edf1
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 0 deletions.
47 changes: 47 additions & 0 deletions scripts/start.js
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`
);
})
);
107 changes: 107 additions & 0 deletions src/virtual-keyboard/vue-mathlive.js
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();
},
},
};
1 change: 1 addition & 0 deletions test/__mocks__/styleMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 'MOCK_STYLE';

0 comments on commit 7b3edf1

Please sign in to comment.