@aphexcms/cms-core 9.0.0 → 9.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/generate-types.d.ts.map +1 -1
- package/dist/cli/generate-types.js +197 -8
- package/dist/cli/generate-types.js.map +1 -1
- package/dist/components/AdminApp.svelte +46 -137
- package/dist/components/AdminApp.svelte.d.ts.map +1 -1
- package/dist/components/admin/DocumentEditor.svelte +237 -206
- package/dist/components/admin/DocumentEditor.svelte.d.ts.map +1 -1
- package/dist/components/admin/DocumentVersionPanel.svelte +3 -2
- package/dist/components/admin/DocumentVersionPanel.svelte.d.ts.map +1 -1
- package/dist/components/admin/MediaBrowser.svelte +22 -4
- package/dist/components/admin/MediaBrowser.svelte.d.ts.map +1 -1
- package/dist/components/admin/ObjectModal.svelte +62 -75
- package/dist/components/admin/ObjectModal.svelte.d.ts.map +1 -1
- package/dist/components/admin/SchemaField.svelte +2 -2
- package/dist/components/admin/fields/ArrayField.svelte +9 -1
- package/dist/components/admin/fields/ArrayField.svelte.d.ts.map +1 -1
- package/dist/components/admin/fields/ReferenceField.svelte +37 -8
- package/dist/components/admin/fields/ReferenceField.svelte.d.ts.map +1 -1
- package/dist/components/admin/fields/richtext/PortableTextImageView.svelte +116 -0
- package/dist/components/admin/fields/richtext/PortableTextImageView.svelte.d.ts +12 -0
- package/dist/components/admin/fields/richtext/PortableTextImageView.svelte.d.ts.map +1 -0
- package/dist/components/admin/fields/richtext/PortableTextInlineView.svelte +111 -0
- package/dist/components/admin/fields/richtext/PortableTextInlineView.svelte.d.ts +12 -0
- package/dist/components/admin/fields/richtext/PortableTextInlineView.svelte.d.ts.map +1 -0
- package/dist/components/admin/fields/richtext/PortableTextObjectView.svelte +67 -0
- package/dist/components/admin/fields/richtext/PortableTextObjectView.svelte.d.ts +12 -0
- package/dist/components/admin/fields/richtext/PortableTextObjectView.svelte.d.ts.map +1 -0
- package/dist/components/admin/fields/richtext/RichtextField.svelte +1314 -0
- package/dist/components/admin/fields/richtext/RichtextField.svelte.d.ts +15 -0
- package/dist/components/admin/fields/richtext/RichtextField.svelte.d.ts.map +1 -0
- package/dist/components/admin/fields/richtext/custom-annotation-mark.d.ts +7 -0
- package/dist/components/admin/fields/richtext/custom-annotation-mark.d.ts.map +1 -0
- package/dist/components/admin/fields/richtext/custom-annotation-mark.js +33 -0
- package/dist/components/admin/fields/richtext/portable-text-inline-object.d.ts +11 -0
- package/dist/components/admin/fields/richtext/portable-text-inline-object.d.ts.map +1 -0
- package/dist/components/admin/fields/richtext/portable-text-inline-object.js +31 -0
- package/dist/components/admin/fields/richtext/portable-text-object-node.d.ts +11 -0
- package/dist/components/admin/fields/richtext/portable-text-object-node.d.ts.map +1 -0
- package/dist/components/admin/fields/richtext/portable-text-object-node.js +31 -0
- package/dist/components/admin/fields/richtext/portable-text-serializer.d.ts +38 -0
- package/dist/components/admin/fields/richtext/portable-text-serializer.d.ts.map +1 -0
- package/dist/components/admin/fields/richtext/portable-text-serializer.js +318 -0
- package/dist/components/admin/fields/richtext/svelte-inline-node-view.d.ts +8 -0
- package/dist/components/admin/fields/richtext/svelte-inline-node-view.d.ts.map +1 -0
- package/dist/components/admin/fields/richtext/svelte-inline-node-view.js +67 -0
- package/dist/components/admin/fields/richtext/svelte-node-view.d.ts +8 -0
- package/dist/components/admin/fields/richtext/svelte-node-view.d.ts.map +1 -0
- package/dist/components/admin/fields/richtext/svelte-node-view.js +63 -0
- package/dist/db/interfaces/document.d.ts +8 -2
- package/dist/db/interfaces/document.d.ts.map +1 -1
- package/dist/graphql/resolvers.d.ts.map +1 -1
- package/dist/graphql/resolvers.js +13 -11
- package/dist/graphql/schema.d.ts.map +1 -1
- package/dist/graphql/schema.js +7 -3
- package/dist/lib/components/admin/fields/richtext/custom-annotation-mark.d.ts +7 -0
- package/dist/lib/components/admin/fields/richtext/custom-annotation-mark.d.ts.map +1 -0
- package/dist/lib/components/admin/fields/richtext/custom-annotation-mark.js +34 -0
- package/dist/lib/components/admin/fields/richtext/custom-annotation-mark.js.map +1 -0
- package/dist/lib/components/admin/fields/richtext/portable-text-inline-object.d.ts +11 -0
- package/dist/lib/components/admin/fields/richtext/portable-text-inline-object.d.ts.map +1 -0
- package/dist/lib/components/admin/fields/richtext/portable-text-inline-object.js +32 -0
- package/dist/lib/components/admin/fields/richtext/portable-text-inline-object.js.map +1 -0
- package/dist/lib/components/admin/fields/richtext/portable-text-object-node.d.ts +11 -0
- package/dist/lib/components/admin/fields/richtext/portable-text-object-node.d.ts.map +1 -0
- package/dist/lib/components/admin/fields/richtext/portable-text-object-node.js +32 -0
- package/dist/lib/components/admin/fields/richtext/portable-text-object-node.js.map +1 -0
- package/dist/lib/components/admin/fields/richtext/portable-text-serializer.d.ts +38 -0
- package/dist/lib/components/admin/fields/richtext/portable-text-serializer.d.ts.map +1 -0
- package/dist/lib/components/admin/fields/richtext/portable-text-serializer.js +319 -0
- package/dist/lib/components/admin/fields/richtext/portable-text-serializer.js.map +1 -0
- package/dist/lib/components/admin/fields/richtext/svelte-inline-node-view.d.ts +8 -0
- package/dist/lib/components/admin/fields/richtext/svelte-inline-node-view.d.ts.map +1 -0
- package/dist/lib/components/admin/fields/richtext/svelte-inline-node-view.js +68 -0
- package/dist/lib/components/admin/fields/richtext/svelte-inline-node-view.js.map +1 -0
- package/dist/lib/components/admin/fields/richtext/svelte-node-view.d.ts +8 -0
- package/dist/lib/components/admin/fields/richtext/svelte-node-view.d.ts.map +1 -0
- package/dist/lib/components/admin/fields/richtext/svelte-node-view.js +64 -0
- package/dist/lib/components/admin/fields/richtext/svelte-node-view.js.map +1 -0
- package/dist/lib/db/interfaces/document.d.ts +8 -2
- package/dist/lib/db/interfaces/document.d.ts.map +1 -1
- package/dist/lib/graphql/resolvers.d.ts.map +1 -1
- package/dist/lib/graphql/resolvers.js +13 -11
- package/dist/lib/graphql/resolvers.js.map +1 -1
- package/dist/lib/graphql/schema.d.ts.map +1 -1
- package/dist/lib/graphql/schema.js +7 -3
- package/dist/lib/graphql/schema.js.map +1 -1
- package/dist/lib/local-api/collection-api.d.ts.map +1 -1
- package/dist/lib/local-api/collection-api.js +7 -0
- package/dist/lib/local-api/collection-api.js.map +1 -1
- package/dist/lib/schema-utils/validator.d.ts.map +1 -1
- package/dist/lib/schema-utils/validator.js +5 -1
- package/dist/lib/schema-utils/validator.js.map +1 -1
- package/dist/lib/server/api/routes/assets-by-id.d.ts.map +1 -1
- package/dist/lib/server/api/routes/assets-by-id.js +10 -2
- package/dist/lib/server/api/routes/assets-by-id.js.map +1 -1
- package/dist/lib/server/api/routes/assets-references.d.ts.map +1 -1
- package/dist/lib/server/api/routes/assets-references.js +6 -4
- package/dist/lib/server/api/routes/assets-references.js.map +1 -1
- package/dist/lib/types/schemas.d.ts +27 -0
- package/dist/lib/types/schemas.d.ts.map +1 -1
- package/dist/lib/types/schemas.js +3 -1
- package/dist/lib/types/schemas.js.map +1 -1
- package/dist/local-api/collection-api.d.ts.map +1 -1
- package/dist/local-api/collection-api.js +7 -0
- package/dist/schema-utils/validator.d.ts.map +1 -1
- package/dist/schema-utils/validator.js +5 -1
- package/dist/server/api/routes/assets-by-id.d.ts.map +1 -1
- package/dist/server/api/routes/assets-by-id.js +10 -2
- package/dist/server/api/routes/assets-references.d.ts.map +1 -1
- package/dist/server/api/routes/assets-references.js +6 -4
- package/dist/types/schemas.d.ts +27 -0
- package/dist/types/schemas.d.ts.map +1 -1
- package/dist/types/schemas.js +3 -1
- package/package.json +6 -1
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type PortableTextValue } from './portable-text-serializer.js';
|
|
2
|
+
import type { ArrayField as ArrayFieldType } from '../../../../types/schemas.js';
|
|
3
|
+
interface Props {
|
|
4
|
+
field: ArrayFieldType;
|
|
5
|
+
value: PortableTextValue | null | undefined;
|
|
6
|
+
onUpdate: (value: PortableTextValue) => void;
|
|
7
|
+
validationClasses?: string;
|
|
8
|
+
readonly?: boolean;
|
|
9
|
+
onOpenReference?: (documentId: string, documentType: string) => void;
|
|
10
|
+
organizationId?: string;
|
|
11
|
+
}
|
|
12
|
+
declare const RichtextField: import("svelte").Component<Props, {}, "">;
|
|
13
|
+
type RichtextField = ReturnType<typeof RichtextField>;
|
|
14
|
+
export default RichtextField;
|
|
15
|
+
//# sourceMappingURL=RichtextField.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RichtextField.svelte.d.ts","sourceRoot":"","sources":["../../../../../src/lib/components/admin/fields/richtext/RichtextField.svelte.ts"],"names":[],"mappings":"AA4BA,OAAO,EAGL,KAAK,iBAAiB,EACtB,MAAM,4BAA4B,CAAC;AAIrC,OAAO,KAAK,EAAE,UAAU,IAAI,cAAc,EAAc,MAAM,2BAA2B,CAAC;AASzF,UAAU,KAAK;IACd,KAAK,EAAE,cAAc,CAAC;IACtB,KAAK,EAAE,iBAAiB,GAAG,IAAI,GAAG,SAAS,CAAC;IAC5C,QAAQ,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAC7C,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,eAAe,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,KAAK,IAAI,CAAC;IACrE,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB;AAm+BF,QAAA,MAAM,aAAa,2CAAwC,CAAC;AAC5D,KAAK,aAAa,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AACtD,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Mark } from '@tiptap/core';
|
|
2
|
+
export interface CustomAnnotationOptions {
|
|
3
|
+
annotationType: string;
|
|
4
|
+
onEdit: (attrs: Record<string, unknown>) => void;
|
|
5
|
+
}
|
|
6
|
+
export declare function createAnnotationMark(name: string): Mark<CustomAnnotationOptions, any>;
|
|
7
|
+
//# sourceMappingURL=custom-annotation-mark.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom-annotation-mark.d.ts","sourceRoot":"","sources":["../../../../../src/lib/components/admin/fields/richtext/custom-annotation-mark.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAmB,MAAM,cAAc,CAAC;AAErD,MAAM,WAAW,uBAAuB;IACvC,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;CACjD;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,sCAmChD"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Mark, mergeAttributes } from '@tiptap/core';
|
|
2
|
+
export function createAnnotationMark(name) {
|
|
3
|
+
return Mark.create({
|
|
4
|
+
name: `annotation_${name}`,
|
|
5
|
+
inclusive: false,
|
|
6
|
+
addOptions() {
|
|
7
|
+
return {
|
|
8
|
+
annotationType: name,
|
|
9
|
+
onEdit: () => { }
|
|
10
|
+
};
|
|
11
|
+
},
|
|
12
|
+
addAttributes() {
|
|
13
|
+
return {
|
|
14
|
+
_key: { default: null },
|
|
15
|
+
data: { default: {} }
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
parseHTML() {
|
|
19
|
+
return [{ tag: `span[data-annotation="${name}"]` }];
|
|
20
|
+
},
|
|
21
|
+
renderHTML({ HTMLAttributes }) {
|
|
22
|
+
return [
|
|
23
|
+
'span',
|
|
24
|
+
mergeAttributes(HTMLAttributes, {
|
|
25
|
+
'data-annotation': name,
|
|
26
|
+
class: 'richtext-annotation',
|
|
27
|
+
style: 'border-bottom: 2px dashed currentColor; cursor: pointer;'
|
|
28
|
+
}),
|
|
29
|
+
0
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Node } from '@tiptap/core';
|
|
2
|
+
export interface PortableTextInlineObjectOptions {
|
|
3
|
+
onEdit: (attrs: {
|
|
4
|
+
_type: string;
|
|
5
|
+
_key: string;
|
|
6
|
+
data: Record<string, unknown>;
|
|
7
|
+
}) => void;
|
|
8
|
+
onDelete: (key: string) => void;
|
|
9
|
+
}
|
|
10
|
+
export declare const PortableTextInlineObject: Node<PortableTextInlineObjectOptions, any>;
|
|
11
|
+
//# sourceMappingURL=portable-text-inline-object.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portable-text-inline-object.d.ts","sourceRoot":"","sources":["../../../../../src/lib/components/admin/fields/richtext/portable-text-inline-object.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAmB,MAAM,cAAc,CAAC;AAGrD,MAAM,WAAW,+BAA+B;IAC/C,MAAM,EAAE,CAAC,KAAK,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,KAAK,IAAI,CAAC;IACxF,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CAChC;AAED,eAAO,MAAM,wBAAwB,4CAiCnC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Node, mergeAttributes } from '@tiptap/core';
|
|
2
|
+
import { SvelteInlineNodeViewRenderer } from './svelte-inline-node-view.js';
|
|
3
|
+
export const PortableTextInlineObject = Node.create({
|
|
4
|
+
name: 'portableTextInlineObject',
|
|
5
|
+
group: 'inline',
|
|
6
|
+
inline: true,
|
|
7
|
+
atom: true,
|
|
8
|
+
selectable: true,
|
|
9
|
+
addOptions() {
|
|
10
|
+
return {
|
|
11
|
+
onEdit: () => { },
|
|
12
|
+
onDelete: () => { }
|
|
13
|
+
};
|
|
14
|
+
},
|
|
15
|
+
addAttributes() {
|
|
16
|
+
return {
|
|
17
|
+
_type: { default: null },
|
|
18
|
+
_key: { default: null },
|
|
19
|
+
data: { default: {} }
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
parseHTML() {
|
|
23
|
+
return [{ tag: 'span[data-portable-text-inline]' }];
|
|
24
|
+
},
|
|
25
|
+
renderHTML({ HTMLAttributes }) {
|
|
26
|
+
return ['span', mergeAttributes(HTMLAttributes, { 'data-portable-text-inline': '' }), 0];
|
|
27
|
+
},
|
|
28
|
+
addNodeView() {
|
|
29
|
+
return SvelteInlineNodeViewRenderer(this.options.onEdit, this.options.onDelete);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Node } from '@tiptap/core';
|
|
2
|
+
export interface PortableTextObjectOptions {
|
|
3
|
+
onEdit: (attrs: {
|
|
4
|
+
_type: string;
|
|
5
|
+
_key: string;
|
|
6
|
+
data: Record<string, unknown>;
|
|
7
|
+
}) => void;
|
|
8
|
+
onDelete: (key: string) => void;
|
|
9
|
+
}
|
|
10
|
+
export declare const PortableTextObject: Node<PortableTextObjectOptions, any>;
|
|
11
|
+
//# sourceMappingURL=portable-text-object-node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portable-text-object-node.d.ts","sourceRoot":"","sources":["../../../../../src/lib/components/admin/fields/richtext/portable-text-object-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAmB,MAAM,cAAc,CAAC;AAGrD,MAAM,WAAW,yBAAyB;IACzC,MAAM,EAAE,CAAC,KAAK,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,KAAK,IAAI,CAAC;IACxF,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CAChC;AAED,eAAO,MAAM,kBAAkB,sCAiC7B,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Node, mergeAttributes } from '@tiptap/core';
|
|
2
|
+
import { SvelteNodeViewRenderer } from './svelte-node-view.js';
|
|
3
|
+
export const PortableTextObject = Node.create({
|
|
4
|
+
name: 'portableTextObject',
|
|
5
|
+
group: 'block',
|
|
6
|
+
atom: true,
|
|
7
|
+
draggable: true,
|
|
8
|
+
selectable: true,
|
|
9
|
+
addOptions() {
|
|
10
|
+
return {
|
|
11
|
+
onEdit: () => { },
|
|
12
|
+
onDelete: () => { }
|
|
13
|
+
};
|
|
14
|
+
},
|
|
15
|
+
addAttributes() {
|
|
16
|
+
return {
|
|
17
|
+
_type: { default: null },
|
|
18
|
+
_key: { default: null },
|
|
19
|
+
data: { default: {} }
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
parseHTML() {
|
|
23
|
+
return [{ tag: 'div[data-portable-text-object]' }];
|
|
24
|
+
},
|
|
25
|
+
renderHTML({ HTMLAttributes }) {
|
|
26
|
+
return ['div', mergeAttributes(HTMLAttributes, { 'data-portable-text-object': '' }), 0];
|
|
27
|
+
},
|
|
28
|
+
addNodeView() {
|
|
29
|
+
return SvelteNodeViewRenderer(this.options.onEdit, this.options.onDelete);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { JSONContent } from '@tiptap/core';
|
|
2
|
+
interface PortableTextSpan {
|
|
3
|
+
_type: 'span';
|
|
4
|
+
_key: string;
|
|
5
|
+
text: string;
|
|
6
|
+
marks?: string[];
|
|
7
|
+
}
|
|
8
|
+
export interface PortableTextInlineObject {
|
|
9
|
+
_type: string;
|
|
10
|
+
_key: string;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
export type PortableTextChild = PortableTextSpan | PortableTextInlineObject;
|
|
14
|
+
interface PortableTextMarkDefinition {
|
|
15
|
+
_type: string;
|
|
16
|
+
_key: string;
|
|
17
|
+
[key: string]: unknown;
|
|
18
|
+
}
|
|
19
|
+
interface PortableTextBlock {
|
|
20
|
+
_type: 'block';
|
|
21
|
+
_key: string;
|
|
22
|
+
style?: string;
|
|
23
|
+
children: PortableTextChild[];
|
|
24
|
+
markDefs?: PortableTextMarkDefinition[];
|
|
25
|
+
listItem?: string;
|
|
26
|
+
level?: number;
|
|
27
|
+
}
|
|
28
|
+
export interface PortableTextCustomBlock {
|
|
29
|
+
_type: string;
|
|
30
|
+
_key: string;
|
|
31
|
+
[key: string]: unknown;
|
|
32
|
+
}
|
|
33
|
+
export type PortableTextNode = PortableTextBlock | PortableTextCustomBlock;
|
|
34
|
+
export type PortableTextValue = PortableTextNode[];
|
|
35
|
+
export declare function tiptapToPortableText(doc: JSONContent): PortableTextValue;
|
|
36
|
+
export declare function portableTextToTiptap(value: PortableTextValue): JSONContent;
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=portable-text-serializer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portable-text-serializer.d.ts","sourceRoot":"","sources":["../../../../../src/lib/components/admin/fields/richtext/portable-text-serializer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,UAAU,gBAAgB;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,MAAM,WAAW,wBAAwB;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACvB;AAED,MAAM,MAAM,iBAAiB,GAAG,gBAAgB,GAAG,wBAAwB,CAAC;AAE5E,UAAU,0BAA0B;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACvB;AAED,UAAU,iBAAiB;IAC1B,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,iBAAiB,EAAE,CAAC;IAC9B,QAAQ,CAAC,EAAE,0BAA0B,EAAE,CAAC;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,uBAAuB;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACvB;AAED,MAAM,MAAM,gBAAgB,GAAG,iBAAiB,GAAG,uBAAuB,CAAC;AAC3E,MAAM,MAAM,iBAAiB,GAAG,gBAAgB,EAAE,CAAC;AAwInD,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,WAAW,GAAG,iBAAiB,CAmCxE;AAuED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,iBAAiB,GAAG,WAAW,CAmE1E"}
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
let keyCounter = 0;
|
|
2
|
+
function genKey() {
|
|
3
|
+
return (++keyCounter).toString(36) + Math.random().toString(36).slice(2, 6);
|
|
4
|
+
}
|
|
5
|
+
const DECORATOR_MAP = {
|
|
6
|
+
bold: 'strong',
|
|
7
|
+
italic: 'em',
|
|
8
|
+
underline: 'underline',
|
|
9
|
+
strike: 'strike-through',
|
|
10
|
+
code: 'code'
|
|
11
|
+
};
|
|
12
|
+
const DECORATOR_MAP_REVERSE = Object.fromEntries(Object.entries(DECORATOR_MAP).map(([k, v]) => [v, k]));
|
|
13
|
+
function extractMarksFromNode(node, markDefs) {
|
|
14
|
+
const marks = [];
|
|
15
|
+
if (!node.marks)
|
|
16
|
+
return marks;
|
|
17
|
+
for (const mark of node.marks) {
|
|
18
|
+
const markType = typeof mark === 'string' ? mark : mark.type;
|
|
19
|
+
const markAttrs = typeof mark === 'string' ? {} : mark.attrs || {};
|
|
20
|
+
if (markType === 'link') {
|
|
21
|
+
const key = genKey();
|
|
22
|
+
markDefs.push({
|
|
23
|
+
_type: 'link',
|
|
24
|
+
_key: key,
|
|
25
|
+
href: markAttrs.href || ''
|
|
26
|
+
});
|
|
27
|
+
marks.push(key);
|
|
28
|
+
}
|
|
29
|
+
else if (markType?.startsWith('annotation_')) {
|
|
30
|
+
const annotationType = markType.slice('annotation_'.length);
|
|
31
|
+
const key = markAttrs._key || genKey();
|
|
32
|
+
const existing = markDefs.find((d) => d._key === key);
|
|
33
|
+
if (existing) {
|
|
34
|
+
Object.assign(existing, { _type: annotationType, ...(markAttrs.data || {}) });
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
markDefs.push({
|
|
38
|
+
_type: annotationType,
|
|
39
|
+
_key: key,
|
|
40
|
+
...(markAttrs.data || {})
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
if (!marks.includes(key))
|
|
44
|
+
marks.push(key);
|
|
45
|
+
}
|
|
46
|
+
else if (DECORATOR_MAP[markType]) {
|
|
47
|
+
marks.push(DECORATOR_MAP[markType]);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return marks;
|
|
51
|
+
}
|
|
52
|
+
function prosemirrorBlockToPortableText(node, listItem, level) {
|
|
53
|
+
const markDefs = [];
|
|
54
|
+
const children = [];
|
|
55
|
+
if (node.content) {
|
|
56
|
+
for (const child of node.content) {
|
|
57
|
+
if (child.type === 'text') {
|
|
58
|
+
const marks = extractMarksFromNode(child, markDefs);
|
|
59
|
+
children.push({
|
|
60
|
+
_type: 'span',
|
|
61
|
+
_key: genKey(),
|
|
62
|
+
text: child.text || '',
|
|
63
|
+
marks: marks.length > 0 ? marks : undefined
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
else if (child.type === 'hardBreak') {
|
|
67
|
+
children.push({
|
|
68
|
+
_type: 'span',
|
|
69
|
+
_key: genKey(),
|
|
70
|
+
text: '\n'
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
else if (child.type === 'portableTextInlineObject') {
|
|
74
|
+
const { _type, _key, data } = child.attrs || {};
|
|
75
|
+
children.push({ _type, _key: _key || genKey(), ...data });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (children.length === 0) {
|
|
80
|
+
children.push({ _type: 'span', _key: genKey(), text: '' });
|
|
81
|
+
}
|
|
82
|
+
let style = 'normal';
|
|
83
|
+
if (node.type === 'heading') {
|
|
84
|
+
style = `h${node.attrs?.level || 1}`;
|
|
85
|
+
}
|
|
86
|
+
else if (node.type === 'blockquote') {
|
|
87
|
+
style = 'blockquote';
|
|
88
|
+
}
|
|
89
|
+
const block = {
|
|
90
|
+
_type: 'block',
|
|
91
|
+
_key: genKey(),
|
|
92
|
+
style,
|
|
93
|
+
children,
|
|
94
|
+
markDefs: markDefs.length > 0 ? markDefs : undefined
|
|
95
|
+
};
|
|
96
|
+
if (listItem) {
|
|
97
|
+
block.listItem = listItem;
|
|
98
|
+
block.level = level;
|
|
99
|
+
}
|
|
100
|
+
return block;
|
|
101
|
+
}
|
|
102
|
+
function flattenListItems(node, listType, level, result) {
|
|
103
|
+
if (!node.content)
|
|
104
|
+
return;
|
|
105
|
+
for (const listItem of node.content) {
|
|
106
|
+
if (listItem.type !== 'listItem')
|
|
107
|
+
continue;
|
|
108
|
+
for (const child of listItem.content || []) {
|
|
109
|
+
if (child.type === 'paragraph' || child.type === 'heading') {
|
|
110
|
+
result.push(prosemirrorBlockToPortableText(child, listType, level));
|
|
111
|
+
}
|
|
112
|
+
else if (child.type === 'bulletList' || child.type === 'orderedList') {
|
|
113
|
+
const nestedType = child.type === 'bulletList' ? 'bullet' : 'number';
|
|
114
|
+
flattenListItems(child, nestedType, level + 1, result);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
export function tiptapToPortableText(doc) {
|
|
120
|
+
const blocks = [];
|
|
121
|
+
if (!doc.content)
|
|
122
|
+
return blocks;
|
|
123
|
+
for (const node of doc.content) {
|
|
124
|
+
if (node.type === 'paragraph' || node.type === 'heading') {
|
|
125
|
+
blocks.push(prosemirrorBlockToPortableText(node));
|
|
126
|
+
}
|
|
127
|
+
else if (node.type === 'blockquote') {
|
|
128
|
+
for (const child of node.content || []) {
|
|
129
|
+
if (child.type === 'paragraph') {
|
|
130
|
+
const block = prosemirrorBlockToPortableText(child);
|
|
131
|
+
block.style = 'blockquote';
|
|
132
|
+
blocks.push(block);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
else if (node.type === 'bulletList' || node.type === 'orderedList') {
|
|
137
|
+
const listType = node.type === 'bulletList' ? 'bullet' : 'number';
|
|
138
|
+
flattenListItems(node, listType, 1, blocks);
|
|
139
|
+
}
|
|
140
|
+
else if (node.type === 'codeBlock') {
|
|
141
|
+
const text = node.content?.[0]?.text ?? '';
|
|
142
|
+
blocks.push({
|
|
143
|
+
_type: 'block',
|
|
144
|
+
_key: genKey(),
|
|
145
|
+
style: 'code',
|
|
146
|
+
children: [{ _type: 'span', _key: genKey(), text }],
|
|
147
|
+
markDefs: undefined
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
else if (node.type === 'portableTextObject') {
|
|
151
|
+
const { _type, _key, data } = node.attrs || {};
|
|
152
|
+
blocks.push({ _type, _key: _key || genKey(), ...data });
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return blocks;
|
|
156
|
+
}
|
|
157
|
+
function buildMarkLookup(markDefs) {
|
|
158
|
+
const map = new Map();
|
|
159
|
+
if (markDefs) {
|
|
160
|
+
for (const def of markDefs) {
|
|
161
|
+
map.set(def._key, def);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return map;
|
|
165
|
+
}
|
|
166
|
+
function spansToTiptapContent(children, markDefs) {
|
|
167
|
+
const markLookup = buildMarkLookup(markDefs);
|
|
168
|
+
const result = [];
|
|
169
|
+
for (const child of children) {
|
|
170
|
+
if (child._type !== 'span') {
|
|
171
|
+
const { _type, _key, ...data } = child;
|
|
172
|
+
result.push({
|
|
173
|
+
type: 'portableTextInlineObject',
|
|
174
|
+
attrs: { _type, _key, data }
|
|
175
|
+
});
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
const span = child;
|
|
179
|
+
if (span.text === '\n') {
|
|
180
|
+
result.push({ type: 'hardBreak' });
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
// ProseMirror rejects empty text nodes
|
|
184
|
+
if (!span.text)
|
|
185
|
+
continue;
|
|
186
|
+
const marks = [];
|
|
187
|
+
if (span.marks) {
|
|
188
|
+
for (const markRef of span.marks) {
|
|
189
|
+
const def = markLookup.get(markRef);
|
|
190
|
+
if (def && def._type === 'link') {
|
|
191
|
+
marks.push({
|
|
192
|
+
type: 'link',
|
|
193
|
+
attrs: { href: def.href, target: null, rel: null, class: null }
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
else if (def) {
|
|
197
|
+
const { _type, _key, ...data } = def;
|
|
198
|
+
marks.push({
|
|
199
|
+
type: `annotation_${_type}`,
|
|
200
|
+
attrs: { _key, data }
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
else if (DECORATOR_MAP_REVERSE[markRef]) {
|
|
204
|
+
marks.push({ type: DECORATOR_MAP_REVERSE[markRef] });
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
result.push({
|
|
209
|
+
type: 'text',
|
|
210
|
+
text: span.text,
|
|
211
|
+
...(marks.length > 0 ? { marks } : {})
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
return result;
|
|
215
|
+
}
|
|
216
|
+
export function portableTextToTiptap(value) {
|
|
217
|
+
const doc = { type: 'doc', content: [] };
|
|
218
|
+
if (!value || value.length === 0) {
|
|
219
|
+
doc.content = [{ type: 'paragraph' }];
|
|
220
|
+
return doc;
|
|
221
|
+
}
|
|
222
|
+
let i = 0;
|
|
223
|
+
while (i < value.length) {
|
|
224
|
+
const node = value[i];
|
|
225
|
+
if (node._type !== 'block') {
|
|
226
|
+
const { _type, _key, ...data } = node;
|
|
227
|
+
doc.content.push({
|
|
228
|
+
type: 'portableTextObject',
|
|
229
|
+
attrs: { _type, _key, data }
|
|
230
|
+
});
|
|
231
|
+
i++;
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
const block = node;
|
|
235
|
+
if (block.listItem) {
|
|
236
|
+
const listType = block.listItem === 'number' ? 'orderedList' : 'bulletList';
|
|
237
|
+
const listNode = buildListNode(value, i, listType, block.level || 1);
|
|
238
|
+
doc.content.push(listNode.node);
|
|
239
|
+
i = listNode.nextIndex;
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
if (block.style === 'code') {
|
|
243
|
+
const text = block.children
|
|
244
|
+
.filter((c) => c._type === 'span')
|
|
245
|
+
.map((c) => c.text)
|
|
246
|
+
.join('');
|
|
247
|
+
doc.content.push({
|
|
248
|
+
type: 'codeBlock',
|
|
249
|
+
attrs: { language: null },
|
|
250
|
+
content: text ? [{ type: 'text', text }] : []
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
else if (block.style === 'blockquote') {
|
|
254
|
+
const content = spansToTiptapContent(block.children, block.markDefs);
|
|
255
|
+
doc.content.push({
|
|
256
|
+
type: 'blockquote',
|
|
257
|
+
content: [{ type: 'paragraph', content: content.length > 0 ? content : undefined }]
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
else if (block.style?.startsWith('h')) {
|
|
261
|
+
const level = parseInt(block.style.slice(1), 10);
|
|
262
|
+
const content = spansToTiptapContent(block.children, block.markDefs);
|
|
263
|
+
doc.content.push({
|
|
264
|
+
type: 'heading',
|
|
265
|
+
attrs: { level },
|
|
266
|
+
content: content.length > 0 ? content : undefined
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
const content = spansToTiptapContent(block.children, block.markDefs);
|
|
271
|
+
doc.content.push({
|
|
272
|
+
type: 'paragraph',
|
|
273
|
+
content: content.length > 0 ? content : undefined
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
i++;
|
|
277
|
+
}
|
|
278
|
+
return doc;
|
|
279
|
+
}
|
|
280
|
+
function buildListNode(blocks, startIndex, listType, level) {
|
|
281
|
+
const items = [];
|
|
282
|
+
let i = startIndex;
|
|
283
|
+
while (i < blocks.length) {
|
|
284
|
+
const node = blocks[i];
|
|
285
|
+
if (node._type !== 'block')
|
|
286
|
+
break;
|
|
287
|
+
const block = node;
|
|
288
|
+
if (!block.listItem)
|
|
289
|
+
break;
|
|
290
|
+
const blockLevel = block.level || 1;
|
|
291
|
+
if (blockLevel < level)
|
|
292
|
+
break;
|
|
293
|
+
if (blockLevel === level) {
|
|
294
|
+
const content = spansToTiptapContent(block.children, block.markDefs);
|
|
295
|
+
const itemContent = [{ type: 'paragraph', content }];
|
|
296
|
+
i++;
|
|
297
|
+
const next = i < blocks.length ? blocks[i] : null;
|
|
298
|
+
if (next &&
|
|
299
|
+
next._type === 'block' &&
|
|
300
|
+
next.listItem &&
|
|
301
|
+
(next.level || 1) > level) {
|
|
302
|
+
const nestedType = next.listItem === 'number' ? 'orderedList' : 'bulletList';
|
|
303
|
+
const nested = buildListNode(blocks, i, nestedType, blockLevel + 1);
|
|
304
|
+
itemContent.push(nested.node);
|
|
305
|
+
i = nested.nextIndex;
|
|
306
|
+
}
|
|
307
|
+
items.push({ type: 'listItem', content: itemContent });
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
const nodeType = listType === 'orderedList' ? 'orderedList' : 'bulletList';
|
|
314
|
+
return {
|
|
315
|
+
node: { type: nodeType, content: items },
|
|
316
|
+
nextIndex: i
|
|
317
|
+
};
|
|
318
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { NodeViewRendererProps } from '@tiptap/core';
|
|
2
|
+
import type { NodeView as ProseMirrorNodeView } from '@tiptap/pm/view';
|
|
3
|
+
export declare function SvelteInlineNodeViewRenderer(onEdit: (attrs: {
|
|
4
|
+
_type: string;
|
|
5
|
+
_key: string;
|
|
6
|
+
data: Record<string, unknown>;
|
|
7
|
+
}) => void, onDelete: (key: string) => void): (props: NodeViewRendererProps) => ProseMirrorNodeView;
|
|
8
|
+
//# sourceMappingURL=svelte-inline-node-view.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svelte-inline-node-view.d.ts","sourceRoot":"","sources":["../../../../../src/lib/components/admin/fields/richtext/svelte-inline-node-view.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,KAAK,EAAE,QAAQ,IAAI,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAIvE,wBAAgB,4BAA4B,CAC3C,MAAM,EAAE,CAAC,KAAK,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,KAAK,IAAI,EACvF,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,IAEvB,OAAO,qBAAqB,KAAG,mBAAmB,CAiE1D"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { mount, unmount } from 'svelte';
|
|
2
|
+
import PortableTextInlineView from './PortableTextInlineView.svelte';
|
|
3
|
+
export function SvelteInlineNodeViewRenderer(onEdit, onDelete) {
|
|
4
|
+
return (props) => {
|
|
5
|
+
const wrapper = document.createElement('span');
|
|
6
|
+
wrapper.setAttribute('data-portable-text-inline', '');
|
|
7
|
+
wrapper.setAttribute('data-node-view-wrapper', '');
|
|
8
|
+
wrapper.contentEditable = 'false';
|
|
9
|
+
wrapper.style.display = 'inline';
|
|
10
|
+
let nodeAttrs = props.node.attrs;
|
|
11
|
+
function mountView() {
|
|
12
|
+
return mount(PortableTextInlineView, {
|
|
13
|
+
target: wrapper,
|
|
14
|
+
props: {
|
|
15
|
+
type: nodeAttrs._type,
|
|
16
|
+
nodeKey: nodeAttrs._key,
|
|
17
|
+
data: nodeAttrs.data,
|
|
18
|
+
selected: false,
|
|
19
|
+
onEdit: () => {
|
|
20
|
+
onEdit({
|
|
21
|
+
_type: nodeAttrs._type,
|
|
22
|
+
_key: nodeAttrs._key,
|
|
23
|
+
data: nodeAttrs.data
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
onDelete: () => {
|
|
27
|
+
onDelete(nodeAttrs._key);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
let currentComponent = mountView();
|
|
33
|
+
return {
|
|
34
|
+
dom: wrapper,
|
|
35
|
+
update(node) {
|
|
36
|
+
if (node.type.name !== 'portableTextInlineObject')
|
|
37
|
+
return false;
|
|
38
|
+
nodeAttrs = node.attrs;
|
|
39
|
+
unmount(currentComponent);
|
|
40
|
+
currentComponent = mountView();
|
|
41
|
+
return true;
|
|
42
|
+
},
|
|
43
|
+
selectNode() {
|
|
44
|
+
wrapper.classList.add('ProseMirror-selectednode');
|
|
45
|
+
onEdit({
|
|
46
|
+
_type: nodeAttrs._type,
|
|
47
|
+
_key: nodeAttrs._key,
|
|
48
|
+
data: nodeAttrs.data
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
deselectNode() {
|
|
52
|
+
wrapper.classList.remove('ProseMirror-selectednode');
|
|
53
|
+
},
|
|
54
|
+
destroy() {
|
|
55
|
+
unmount(currentComponent);
|
|
56
|
+
},
|
|
57
|
+
stopEvent(event) {
|
|
58
|
+
if (event.type === 'mousedown' || event.type === 'click')
|
|
59
|
+
return true;
|
|
60
|
+
return false;
|
|
61
|
+
},
|
|
62
|
+
ignoreMutation() {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { NodeViewRendererProps } from '@tiptap/core';
|
|
2
|
+
import type { NodeView as ProseMirrorNodeView } from '@tiptap/pm/view';
|
|
3
|
+
export declare function SvelteNodeViewRenderer(onEdit: (attrs: {
|
|
4
|
+
_type: string;
|
|
5
|
+
_key: string;
|
|
6
|
+
data: Record<string, unknown>;
|
|
7
|
+
}) => void, onDelete: (key: string) => void): (props: NodeViewRendererProps) => ProseMirrorNodeView;
|
|
8
|
+
//# sourceMappingURL=svelte-node-view.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svelte-node-view.d.ts","sourceRoot":"","sources":["../../../../../src/lib/components/admin/fields/richtext/svelte-node-view.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,KAAK,EAAE,QAAQ,IAAI,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAKvE,wBAAgB,sBAAsB,CACrC,MAAM,EAAE,CAAC,KAAK,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,KAAK,IAAI,EACvF,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,IAEvB,OAAO,qBAAqB,KAAG,mBAAmB,CA8D1D"}
|