How do you map changes between a CodeMirror component and an array of objects?
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 25/100
- Tipo di issue
- Documentazione
- Chiarezza
- Da chiarire
- Stato di attività
- Ferma
- Stack tecnologico
- react, typescript
- Ambito
- developer-experience, documentation
Direzione di ricerca
Inizia con l’esempio InputWithFields e la relativa logica handleTextChange nell’issue; non sono indicati né un file del repository né un test. Determina dove collocare un esempio di integrazione di CodeMirror/RangeSet, quindi documenta come dovrebbe essere gestito questo caso d’uso con un array di oggetti e cosa dovrebbero produrre gli aggiornamenti riusciti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
I have an array of objects that are represented in a CodeMirror component. I'm trying to work out how to map changes in the CodeMirror to the object. I'm using a RangeSet to hold the underlying object. I was expecting I could use RangeSet.map() to apply the changes from the CodeMirror onto the object RangeSet. I'm not seeing that happen.
Is there an example that can help me understand how to handle this use case in a good way?
type Text = { type: "text"; textValue: string };
type Field = {
type: "field";
textValue: string;
field: {
fieldId: string;
};
};
export type TextWithField = (Text | Field)[];
class TextOrFieldRange extends RangeValue {
type: "text" | "field";
textOrField: Text | Field;
theRange;
constructor(
from: number,
to: number,
type: "text" | "field",
textOrField: Text | Field
) {
super();
this.type = type;
this.textOrField = { ...textOrField };
this.theRange = this.range(from, to);
}
eq(other: RangeValue): boolean {
return (
other instanceof TextOrFieldRange &&
this.type === other.type &&
this.theRange.from === other.theRange.from &&
this.theRange.to === other.theRange.to
);
}
}
const InputWithFields = ({
textWithFields,
setTextWithFields,
}: {
textWithFields: TextWithField;
setTextWithFields: (textWithFields: TextWithField) => void;
}) => {
const rangeBuilder = new RangeSetBuilder<TextOrFieldRange>();
let combinedText = "";
const fieldRanges: [number, number][] = [];
textWithFields.forEach((item) => {
const start = combinedText.length;
combinedText += item.textValue;
const end = combinedText.length;
rangeBuilder.add(
start,
end,
new TextOrFieldRange(start, combinedText.length, item.type, item)
);
item.type == "field" && fieldRanges.push([start, end]);
});
const combinedRanges = rangeBuilder.finish();
const handleTextChange = (value: string, viewUpdate: ViewUpdate) => {
const newRanges = combinedRanges.map(viewUpdate.changes.desc);
const iterator = newRanges.iter();
const newTextWithFields: TextWithField = [];
while (iterator.value !== null) {
newTextWithFields.push(iterator.value.textOrField);
iterator.next();
}
setTextWithFields(newTextWithFields);
};
const highlightRanges = rangeHighlighter(fieldRanges);
return (
<CodeMirror
value={combinedText}
onChange={handleTextChange}
theme="none"
basicSetup={false}
editable={true}
extensions={[...extensions, highlightRanges]}
maxWidth="100%"
height="100px"
/>
);
};
- Lingua principale
- TypeScript
- Stelle
- 2.3k
- Fork
- 162
- Merge medio
- 2h 41m
- PR unite (30g)
- 1
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di uiwjs/react-codemirror
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
uiwjs/react-codemirror#766 · 2 commenti ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
uiwjs/react-codemirror#765 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
uiwjs/react-codemirror#772 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
uiwjs/react-codemirror#770 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 48/100
uiwjs/react-codemirror#767 · 2 commenti ·
Tutte le issue di uiwjs/react-codemirror
Issue simili
-
area: aria/combobox gemini-triaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
angular/components#33973 ·
I maintainer di solito rispondono entro 1 giorno
-
bug priority: P2
Difficoltà 1/5 1-3 ore Idoneità per principianti 84/100
I maintainer di solito rispondono entro 1 giorno
-
[bug] status, list and push crash with an uncaught NotInitializedError stack trace when teamai is not initializedForse già presa @jay23606 l’ha presa oggi. Apertabug good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
Tencent/teamai-cli#1227 ·
I maintainer di solito rispondono entro 1 giorno
-
[Tool]: YapAperta
Difficoltà 1/5 1-3 ore Idoneità per principianti 62/100
withkarann/aifoxx#417 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
sindresorhus/eslint-plugin-unicorn#3921 ·
I maintainer di solito rispondono entro 1 giorno