Skip to content

Commit

Permalink
Merge pull request #120 from lblod/feature/vendor-environment
Browse files Browse the repository at this point in the history
Feature/vendor environment
  • Loading branch information
nvdk authored Jul 1, 2021
2 parents 08a435c + e978914 commit f5145f9
Show file tree
Hide file tree
Showing 23 changed files with 484 additions and 131 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# misc
/coverage/
!.*
/tests/dummy/app/config/sample-data.js
/tests/dummy/app/config/sample-data.ts

# ember-try
/.node_modules.ember-try/
Expand Down
28 changes: 19 additions & 9 deletions addon/model/model-position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,16 +318,27 @@ export default class ModelPosition {
* @return string the collected characters, in display order
*/
charactersBefore(amount: number): string {

let cur = this.nodeBefore();
let counter = 0;
const result = [];

while (ModelNode.isModelText(cur) && counter < amount) {
const amountToCollect = amount - counter;
const length = cur.content.length;
for (let i = 0; i < amountToCollect; i++) {
result.push(cur.content.charAt(length - 1 - i));
let startSearch;
if (cur === this.nodeAfter()) {
startSearch = this.parentOffset - cur.getOffset();
} else {
startSearch = cur.length;
}

let i = 0;
let charIndex = startSearch - 1 - i;
while (i < amountToCollect && charIndex >= 0) {
result.push(cur.content.charAt(startSearch - 1 - i));
counter++;
i++;
charIndex = startSearch - 1 - i;
}
cur = cur.previousSibling;
}
Expand Down Expand Up @@ -355,21 +366,20 @@ export default class ModelPosition {
if (newOffset < 0) {
newOffset = 0;
}
if(newOffset > maxOffset) {
if (newOffset > maxOffset) {
newOffset = maxOffset;
}
return ModelPosition.fromInElement(this.parent, newOffset);
}

//this returns true if the position is inside a text node (not right before not right after)
isInsideText(): boolean{
if(
isInsideText(): boolean {
if (
(this.nodeAfter() == this.nodeBefore()) &&
(ModelNode.isModelText(this.nodeAfter()) && ModelNode.isModelText(this.nodeBefore()))
){
) {
return true;
}
else{
} else {
return false;
}
}
Expand Down
4 changes: 2 additions & 2 deletions addon/model/model-range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export default class ModelRange {
}

collapse(toLeft = false): void {
if(toLeft) {
if (toLeft) {
this.end = this.start;
} else {
this.start = this.end;
Expand Down Expand Up @@ -279,7 +279,7 @@ export default class ModelRange {
}

toString(): string {
return `{[${this.start.path.toString()}] - [${this.end.path.toString()}]}`;
return `ModelRange<[${this.start.path.toString()}] - [${this.end.path.toString()}]>`;

}
}
Expand Down
5 changes: 3 additions & 2 deletions addon/model/util/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ModelNode from "@lblod/ember-rdfa-editor/model/model-node";
import {ModelNodeFinderFilter, ModelNodeFinderPredicate} from "@lblod/ember-rdfa-editor/model/util/model-node-finder";
import RdfaDocument from "@lblod/ember-rdfa-editor/utils/rdfa/rdfa-document";

export type HtmlTag = keyof HTMLElementTagNameMap;

Expand All @@ -24,6 +25,6 @@ export enum PropertyState {
export interface FilterAndPredicate<T extends ModelNode> {
filter?: ModelNodeFinderFilter<T>,
predicate?: ModelNodeFinderPredicate<T>


}

export type RdfaEditorInitializer = (rdfaEditor: RdfaDocument) => void;
19 changes: 18 additions & 1 deletion addon/utils/logging-utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import config from 'ember-get-config';
import {defaultReporter, Diary, diary, LogEvent, LogLevels, Reporter} from 'diary';
import {compare} from 'diary/utils';
import ModelRange from "@lblod/ember-rdfa-editor/model/model-range";

// this array is sorted from lowest to highest "level"
// aka setting loglevel to "info" will include info and everything to the right of it
Expand Down Expand Up @@ -138,4 +139,20 @@ export function logMethod(message: string | MethodMessageFunc = defaultLogMethod
};
}

export const logExecute = logMethod(undefined, {scopePrefix: "command"});
export const logExecute = logMethod(
(_methodName: string, ...args) => {
const mappedArgs = args.map(arg => {
if (arg instanceof ModelRange) {
return arg.toString();
}
if (typeof arg === "string") {
return `string<"${arg}", ${arg.length}>`;
} else {
return arg;
}
}
);
return ["Executing with args:", ...mappedArgs];

}, {scopePrefix: "command"});

29 changes: 29 additions & 0 deletions addon/utils/rdfa/rdfa-document.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import PernetRawEditor from '../ce/pernet-raw-editor';
import xmlFormat from 'xml-formatter';
import HTMLExportWriter from '@lblod/ember-rdfa-editor/model/writers/html-export-writer';
import ModelRange from '@lblod/ember-rdfa-editor/model/model-range';

Expand Down Expand Up @@ -28,6 +29,34 @@ export default class RdfaDocument {
this._editor.executeCommand("insert-html", html, range);
}

get xmlContent() {
return (this._editor.model.toXml() as Element).innerHTML;
}

set xmlContent(xml: string) {
const root = this._editor.model.rootModelNode;
const range = ModelRange.fromPaths(root, [0], [root.getMaxOffset()]);
this._editor.executeCommand("insert-xml", xml, range);
}

get xmlContentPrettified() {
const root = this._editor.model.toXml() as Element;
let result = '';
for (const child of root.childNodes) {

let formatted;
try {
formatted = xmlFormat((child as Element).outerHTML);
} catch (e) {
formatted = (child as Element).outerHTML;
}
result += formatted;

}
return result;
}


setHtmlContent(html: string) {
this.htmlContent = html;
}
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,22 @@
"ember-classic-decorator": "^1.0.3",
"ember-cli-babel": "^7.21.0",
"ember-cli-htmlbars": "^5.2.0",
"ember-cli-typescript": "^4.2.1",
"ember-concurrency": "^1.0.0",
"ember-concurrency-decorators": "^1.0.0",
"ember-concurrency-ts": "^0.2.0",
"ember-decorators": "^6.1.1",
"ember-feature-flags": "^6.0.0",
"ember-focus-trap": "^0.5.0",
"ember-intl": "^5.6.2",
"ember-truth-helpers": "^2.0.0",
"mdn-polyfills": "^5.16.0",
"ember-intl": "^5.6.2",
"ember-cli-typescript": "^4.2.1"
"xml-formatter": "^2.4.0"
},
"devDependencies": {
"@codemirror/basic-setup": "^0.18.2",
"@codemirror/lang-html": "^0.18.1",
"@codemirror/lang-xml": "^0.18.0",
"@glimmer/component": "^1.0.1",
"@types/common-tags": "^1.8.0",
"@types/ember": "^3.1.1",
Expand Down
12 changes: 5 additions & 7 deletions tests/dummy/app/app.js → tests/dummy/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import Resolver from 'ember-resolver';
import loadInitializers from 'ember-load-initializers';
import config from 'dummy/config/environment';

const App = Application.extend({
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix,
Resolver: Resolver
});
export default class App extends Application {
modulePrefix = config.modulePrefix;
podModulePrefix = config.podModulePrefix;
Resolver = Resolver;
}

loadInitializers(App, config.modulePrefix);

export default App;
File renamed without changes.
File renamed without changes.
43 changes: 0 additions & 43 deletions tests/dummy/app/controllers/application.js

This file was deleted.

Loading

0 comments on commit f5145f9

Please sign in to comment.