Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ packages:
- xwiki-platform-core/xwiki-platform-node/src/main/node/core/ds/api
- xwiki-platform-core/xwiki-platform-node/src/main/node/core/fn-utils
- xwiki-platform-core/xwiki-platform-node/src/main/node/core/icons
- xwiki-platform-core/xwiki-platform-node/src/main/node/core/link-modal/link-modal-ui
- xwiki-platform-core/xwiki-platform-node/src/main/node/core/link-suggest/link-suggest-api
- xwiki-platform-core/xwiki-platform-node/src/main/node/core/livedata/livedata-api
- xwiki-platform-core/xwiki-platform-node/src/main/node/core/livedata/livedata-componentstore
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"extends": "../../../api-extractor.json"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"link-modal.buttons.submit": "OK",
"link-modal.buttons.cancel": "Cancel",

"link-modal.config.target-type": "Link type",
"link-modal.config.display-text": "Display text",
"link-modal.config.options": "Options",
"link-modal.config.open-new-tab": "Open in a new tab",

"link-modal.target-types.url.label": "URL",
"link-modal.target-types.url.url": "URL",

"link-modal.target-types.email.label": "E-mail",
"link-modal.target-types.email.address": "E-mail address",
"link-modal.target-types.email.subject": "Message subject",
"link-modal.target-types.email.body": "Message body",

"link-modal.target-types.page.label": "Page",
"link-modal.target-types.page.reference": "Page reference",
"link-modal.target-types.page.query-string": "Query string",
"link-modal.target-types.page.anchor": "Anchor",

"link-modal.target-types.attachment.label": "Attachment",
"link-modal.target-types.attachment.reference": "Attachment reference",
"link-modal.target-types.attachment.query-string": "Query string"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"name": "@xwiki/link-modal-ui",
"version": "18.3.0-SNAPSHOT",
"license": "LGPL 2.1",
"author": "XWiki Org Community <contact@xwiki.org>",
"homepage": "https://xwiki.org/",
"repository": {
"type": "git",
"directory": "xwiki-platform-core/xwiki-platform-node/src/main/node/link-modal/link-modal-ui",
"url": "git+https://github.com/xwiki/xwiki-platform.git"
},
"bugs": {
"url": "https://jira.xwiki.org/projects/XWIKI/"
},
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./src/index.ts"
}
},
"main": "./src/index.ts",
"files": [
"dist",
"src",
"!src/**/*.spec.*",
"!src/**/*.test.*",
"!src/**/__tests__"
],
"scripts": {
"api-extractor:ci": "api-extractor run",
"api-extractor:local": "api-extractor run --local",
"build": "vite build",
"clean": "rimraf dist",
"lint": "eslint \"./src/**/*.{ts,tsx,vue}\" --max-warnings=0",
"test": "vitest --run",
"typecheck": "vue-tsc"
},
"types": "./dist/index.d.ts",
"dependencies": {
"@blocknote/core": "catalog:",
"@xwiki/platform-attachments-api": "workspace:*",
"@xwiki/platform-api": "workspace:*",
"@xwiki/platform-document-api": "workspace:*",
"@xwiki/platform-dsapi": "workspace:*",
"@xwiki/platform-fn-utils": "workspace:*",
"@xwiki/platform-icons": "workspace:*",
"@xwiki/platform-link-suggest-api": "workspace:*",
"@xwiki/platform-model-api": "workspace:*",
"@xwiki/platform-model-reference-api": "workspace:*",
"@xwiki/platform-model-remote-url-api": "workspace:*",
"lodash-es": "catalog:",
"vue-i18n": "catalog:"
},
"peerDependencies": {
"inversify": "7.x",
"reflect-metadata": "0.x",
"vue": "3.x"
},
"devDependencies": {
"@microsoft/api-extractor": "catalog:",
"@types/lodash-es": "catalog:",
"@xwiki/platform-dev-config": "workspace:*",
"@xwiki/platform-tool-tsconfig": "workspace:*",
"@xwiki/platform-tool-viteconfig": "workspace:*",
"eslint": "catalog:",
"inversify": "catalog:",
"reflect-metadata": "catalog:",
"typescript": "catalog:",
"vite": "catalog:",
"vitest": "catalog:",
"vitest-mock-extended": "catalog:",
"vue": "catalog:",
"vue-tsc": "catalog:"
},
"publishConfig": {
"exports": {
".": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.es.js"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.umd.js"
}
}
},
"main": "./dist/index.es.js",
"types": "./dist/index.d.ts"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

import { tryFallible } from "@xwiki/platform-fn-utils";
import { EntityType } from "@xwiki/platform-model-api";
import type { LinkTarget } from "./data/linkType";
import type { RemoteURLParser } from "@xwiki/platform-model-remote-url-api";

export function parseLinkTarget(
url: string,
remoteURLParser: RemoteURLParser,
): LinkTarget {
// When no URL is input, show the "page" link selector by default
if (url.trim() === "") {
return { type: "page", config: { ref: null } };
}

const ref = tryFallible(() => remoteURLParser.parse(url));

switch (ref?.type) {
case EntityType.DOCUMENT:
return {
type: "page",
config: {
ref,
// TODO
anchor: undefined,
// TODO
queryString: undefined,
},
};

case EntityType.ATTACHMENT:
return {
type: "attachment",
config: {
ref,
// TODO
queryString: undefined,
},
};
}

const parsedUrl = tryFallible(() => new URL(url));

if (parsedUrl?.protocol === "mailto:") {
const params = new URLSearchParams(parsedUrl.searchParams);

return {
type: "email",
config: {
address: parsedUrl.pathname,
messageSubject: params.get("subject") ?? undefined,
messageBody: params.get("body") ?? undefined,
},
};
}

return { type: "url", config: { url } };
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
import type {
AttachmentReference,
DocumentReference,
} from "@xwiki/platform-model-api";

type LinkData = {
displayText: string;
newTab?: boolean;
target: LinkTarget;
};

type LinkTarget =
| { type: "page"; config: LinkPageConfig }
| { type: "attachment"; config: LinkAttachmentConfig }
| { type: "url"; config: LinkUrlConfig }
| { type: "email"; config: LinkEmailConfig };

type LinkPageConfig = {
ref: DocumentReference | null;
queryString?: string;
anchor?: string;
};

type LinkAttachmentConfig = {
ref: AttachmentReference | null;
queryString?: string;
};

type LinkUrlConfig = {
url: string;
};

type LinkEmailConfig = {
address: string;
messageSubject?: string;
messageBody?: string;
};

export type {
LinkAttachmentConfig,
LinkData,
LinkEmailConfig,
LinkPageConfig,
LinkTarget,
LinkUrlConfig,
};
Loading