Giter Club home page Giter Club logo

pica-editor's Introduction

pica-editor

Test and build npm release

PICA+ record display and editor as Vue3 component based on CodeMirror.

Screenshot

Usage

Try online at https://gbv.github.io/pica-editor/!

Installation

Direct use as UMD module in the browser

First include Vue.js 3 and CodeMirror libraries and CodeMirror CSS:

<script src="https://unpkg.com/[email protected]"></script>
<script src="https://unpkg.com/codemirror"></script>
<link rel="stylesheet" href="https://unpkg.com/codemirror/lib/codemirror.css">

Then include the pica-editor library and its CSS file.

<script src="https://unpkg.com/pica-editor"></script>
<link rel="stylesheet" href="https://unpkg.com/pica-editor/dist/pica-editor.css">

Finally create a Vue application that registers the PicaEditor component and make use of the <pica-editor> element:

<div id="app">
  ...
  <pica-editor>
    <pre>003@ $012345</pre>
  </pica-editor>
  ...
</div>
<script>
  Vue.createApp({
    components: { PicaEditor }
    // ...extend your Vue app
  }).mount("#app")
</script>

Use as ES Module in Vue web applications

We recommend to build your application with vite so Vue modules can be used as single file components (.vue files). In you HTML page include CSS files of CodeMirror and PicaEditor:

<link rel="stylesheet" href="https://unpkg.com/codemirror/lib/codemirror.css">
<link rel="stylesheet" href="https://unpkg.com/pica-editor/dist/pica-editor.css">

<div id="app"></div>
<script type="module" src="main.js"></script>

In a JavaScript module main.js:

import { createApp } from "vue"
import App from "./App.vue"

const app = createApp(App)
app.mount("#app")

In your Vue application:

<template>
  <div>
    <pica-editor>
      <pre>003@ $012345</pre>
    </pica-editor>
  </div>
</template>

<script>
import PicaEditor from "pica-editor"

export default {
  components: { PicaEditor }
  // ...extend your Vue app
}
</script>

The sub-component PicaLoader can also be used independently:

const { PicaLoader } = PicaEditor.components

Configuration

Editor instances can be configured with:

prop type description
unAPI String unAPI base URL to load records from
dbkey String database key to load records from via unAPI
ppn String record PPN to load
xpn String optional flag to control record expansion (default: offline, alternatively online)
filter Function/Boolean function to filter records when loaded or set
editable Boolean whether PICA record can be edited
avram Object/URL Avram Schema with definition of fields and subfields
header Boolean show/hide header (default true)
footer Boolean show/hide footer (default show only if field info is available)
databases Array array of databases to select from

The component emits three events:

  • update:record when the parsed PICA record has been changed
  • update:dbkey when the database has been changed

Databases, if given, are expected to be objects of this form:

{
  dbkey: "mandatory database key",
  title: { de: "German database name (optional)" }
  picabase: "base URL of catalog to link into (optional)"
}

To reflect selection change of database and ppn enable two-way binding:

<pica-editor :databases="[..]" v-model:dbkey="dbkey" v-model:ppn="ppn" ... />

The components provides methods:

  • setRecord to set the PICA record in PICA/JSON structure
  • setText to set the PICA record in PICA Plain syntax
  • load to load a PICA record via unAPI (automatically triggered when properties ppn and/or dbkey are modified)

When filter is set to true, records are filtered to the current avram schema.

For configuration of PicaLoader component see its source code.

Development

During development run the sample application in example/ using vite:

npm run dev

To create distribution files in dist/:

npm run build

The documentation page docs/index.html loads local distribution files if opened at localhost and published distribution files otherwise.

All commits should be done to the dev branch or to feature branches. For releases run npm run release minor or npm run release patch, this automatically tags and merges into the release branch and pushes to GitHub where the release is published at https://www.npmjs.com/package/pica-editor and as GitHub release.

LICENSE

MIT License

pica-editor's People

Contributors

nichtich avatar stefandesu avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

nirvananimbusa

pica-editor's Issues

Range fields are shown as not repeatable

e.g. K10plus PPN 1724924311:

045Q/01 $a42.60$Ahttps://coli-conc.gbv.de/api/mappings/d3efcd94-6c44-4c89-a996-0bac8f2bd187
045Q/02 $9106416006$VTkv$a48.40$jForstwirtschaft
045Q/03 $9106408968$VTkv$a48.66$jJagd$XLand- und Forstwirtschaft

Add link to unAPI

With dropdown of format. Demo could also show target format below the record for comparision.

Store result lists in local storage

Requires #27 and/or PICA+ upload into the browser storage plus a user interface to show, create, and remove result lists.

Note WinIBW has a similar concept with result sets.

Extend filter option

  • Boolean true to filter to Avram schema
  • Array or string with list of PICA Path expressions to filter against

Extend use of TAB

  • Use TAB+left to go backwards
  • Use TAB+down to go to next field, TAB+up to previous field
  • Go to start of record after end has been reached

Support record linking

  • Subfields defined as PPN (e.g. 041A/00-99 $9) could be linked to their records
  • Typeahead suggest on linking fields

Select full subfield value on double click

Configure mouse event in CodeMirror:

      configureMouse: (cm, repeat, event) => {
        if (repeat==="double") {
          // TODO: select full subfield value
          //console.log(cm, repeat, event)
        }
        return {}
      },

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.