@sanity/hierarchical-document-list 0.1.0-next.2 → 0.1.0-next.3

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/README.md CHANGED
@@ -6,6 +6,8 @@ Plugin for editing hierarchical references in the [Sanity studio](https://www.sa
6
6
 
7
7
  ⚠️ **Compatibility:** This plugin requires Sanity Studio [version 2.25.0](https://github.com/sanity-io/sanity/releases/tag/v2.25.0) or higher.
8
8
 
9
+ If you're looking for a way to order documents on a flat list, refer to [@sanity/orderable-document-list](https://github.com/sanity-io/orderable-document-list).
10
+
9
11
  ## Getting started
10
12
 
11
13
  ```bash
@@ -31,7 +31,7 @@ const TreeDeskStructure = (props) => {
31
31
  return (_jsx(DeskWarning, { title: "Invalid configuration", subtitle: "The `documentType` passed to `createDeskHiearchy` isn't live editable. \\nTo continue using this plugin, add `liveEdit: true` to your custom schema type or unset `documentType` in your hierarchy configuration." }, void 0));
32
32
  }
33
33
  if (draft?._id) {
34
- return (_jsx(DeskWarning, { title: "This hierarchy tree contains a draft", subtitle: "Click on the button below to publish your draft in order to continue editing the live\n published document.", children: _jsx(Button, { fontSize: 1, tone: "positive", text: "Publish draft", icon: PublishIcon, onClick: () => {
34
+ return (_jsx(DeskWarning, { title: "This hierarchy tree contains a draft", subtitle: "Click on the button below to publish your draft in order to continue editing the live\r\n published document.", children: _jsx(Button, { fontSize: 1, tone: "positive", text: "Publish draft", icon: PublishIcon, onClick: () => {
35
35
  ops.publish?.execute?.();
36
36
  push({
37
37
  status: 'info',
@@ -5,10 +5,10 @@ import { EditIcon, PublishIcon } from '@sanity/icons';
5
5
  import { Box, Inline, Text, Tooltip } from '@sanity/ui';
6
6
  export function TimeAgo({ time }) {
7
7
  const timeAgo = useTimeAgo(time);
8
- return _jsxs("span", { title: timeAgo, children: [timeAgo, " ago"] }, void 0);
8
+ return (_jsxs("span", { title: timeAgo, children: [timeAgo, timeAgo.toLowerCase().trim().startsWith('just now') ? '' : ' ago'] }, void 0));
9
9
  }
10
- const PublishedStatus = ({ document }) => (_jsx(Tooltip, { content: _jsx(Box, { padding: 2, children: _jsx(Text, { size: 1, children: document ? (_jsxs(_Fragment, { children: ["Published ", document._updatedAt && _jsx(TimeAgo, { time: document._updatedAt }, void 0)] }, void 0)) : (_jsx(_Fragment, { children: "Not published" }, void 0)) }, void 0) }, void 0), children: _jsx(TextWithTone, { tone: "positive", dimmed: !document, muted: !document, size: 1, children: _jsx(PublishIcon, {}, void 0) }, void 0) }, void 0));
11
- const DraftStatus = ({ document }) => (_jsx(Tooltip, { content: _jsx(Box, { padding: 2, children: _jsx(Text, { size: 1, children: document ? (_jsxs(_Fragment, { children: ["Edited ", document?._updatedAt && _jsx(TimeAgo, { time: document?._updatedAt }, void 0)] }, void 0)) : (_jsx(_Fragment, { children: "No unpublished edits" }, void 0)) }, void 0) }, void 0), children: _jsx(TextWithTone, { tone: "caution", dimmed: !document, muted: !document, size: 1, children: _jsx(EditIcon, {}, void 0) }, void 0) }, void 0));
10
+ const PublishedStatus = ({ document }) => (_jsx(Tooltip, { portal: true, content: _jsx(Box, { padding: 2, children: _jsx(Text, { size: 1, children: document ? (_jsxs(_Fragment, { children: ["Published ", document._updatedAt && _jsx(TimeAgo, { time: document._updatedAt }, void 0)] }, void 0)) : (_jsx(_Fragment, { children: "Not published" }, void 0)) }, void 0) }, void 0), children: _jsx(TextWithTone, { tone: "positive", dimmed: !document, muted: !document, size: 1, children: _jsx(PublishIcon, {}, void 0) }, void 0) }, void 0));
11
+ const DraftStatus = ({ document }) => (_jsx(Tooltip, { portal: true, content: _jsx(Box, { padding: 2, children: _jsx(Text, { size: 1, children: document ? (_jsxs(_Fragment, { children: ["Edited ", document?._updatedAt && _jsx(TimeAgo, { time: document?._updatedAt }, void 0)] }, void 0)) : (_jsx(_Fragment, { children: "No unpublished edits" }, void 0)) }, void 0) }, void 0), children: _jsx(TextWithTone, { tone: "caution", dimmed: !document, muted: !document, size: 1, children: _jsx(EditIcon, {}, void 0) }, void 0) }, void 0));
12
12
  // Adapted from @sanity\desk-tool\src\components\paneItem\helpers.tsx
13
13
  const DocumentPreviewStatus = ({ draft, published }) => {
14
14
  return (_jsxs(Inline, { space: 4, children: [_jsx(PublishedStatus, { document: published }, void 0), _jsx(DraftStatus, { document: draft }, void 0)] }, void 0));
@@ -19,6 +19,6 @@ const NodeActions = ({ nodeProps }) => {
19
19
  return (_jsx(IntentLink, { ...restProps, intent: "edit", params: { id: reference?._ref, type: docType }, target: "_blank", rel: "noopener noreferrer", ref: _ref }, void 0));
20
20
  }), [reference?._ref, docType]);
21
21
  const isValid = !!node.publishedId;
22
- return (_jsx(MenuButton, { button: _jsx(Button, { padding: 2, mode: "bleed", icon: EllipsisVerticalIcon }, void 0), id: `hiearchical-doc-list--${node._key}-menuButton`, menu: _jsxs(Menu, { children: [_jsx(MenuItem, { text: "Remove from list", tone: "critical", icon: RemoveCircleIcon, onClick: () => operations.removeItem(nodeProps) }, void 0), _jsx(MenuItem, { text: "Duplicate", icon: CopyIcon, disabled: !isValid, onClick: () => operations.duplicateItem(nodeProps) }, void 0), _jsx(MenuDivider, {}, void 0), _jsx(MenuItem, { text: "Open in new tab", icon: LaunchIcon, disabled: !isValid, as: OpenLink, "data-as": "a" }, void 0)] }, void 0), placement: "right", popover: { portal: true, tone: 'default' } }, void 0));
22
+ return (_jsx(MenuButton, { button: _jsx(Button, { padding: 2, mode: "bleed", icon: EllipsisVerticalIcon }, void 0), id: `hiearchical-doc-list--${node._key}-menuButton`, menu: _jsxs(Menu, { children: [_jsx(MenuItem, { text: "Remove from list", tone: "critical", icon: RemoveCircleIcon, onClick: () => operations.removeItem(nodeProps) }, void 0), _jsx(MenuItem, { text: "Duplicate item", icon: CopyIcon, disabled: !isValid, onClick: () => operations.duplicateItem(nodeProps) }, void 0), _jsx(MenuDivider, {}, void 0), _jsx(MenuItem, { text: "Open in new tab", icon: LaunchIcon, disabled: !isValid, as: OpenLink, "data-as": "a" }, void 0)] }, void 0), placement: "right", popover: { portal: true, tone: 'default' } }, void 0));
23
23
  };
24
24
  export default NodeActions;
@@ -1,5 +1,5 @@
1
1
  import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
- import { Card, Stack, Text } from '@sanity/ui';
2
+ import { Box, Card, Stack, Text } from '@sanity/ui';
3
3
  const PlaceholderDropzone = (props) => {
4
4
  const isValid = props.isOver && props.canDrop;
5
5
  const isInvalid = props.isOver && !props.canDrop;
@@ -10,8 +10,8 @@ const PlaceholderDropzone = (props) => {
10
10
  if (isInvalid) {
11
11
  tone = 'caution';
12
12
  }
13
- return (_jsx(Card, { padding: 5, radius: 2, border: true, tone: tone, style: {
14
- borderStyle: props.isOver ? undefined : 'dashed'
15
- }, children: _jsxs(Stack, { space: 2, style: { textAlign: 'center' }, children: [_jsxs(Text, { size: 2, as: "h2", muted: true, children: [!props.isOver && props.title, isValid && 'Drop here', isInvalid && 'Invalid location or element'] }, void 0), props.subtitle && _jsx(Text, { size: 1, children: props.subtitle }, void 0), props.children] }, void 0) }, void 0));
13
+ return (_jsx(Box, { padding: 3, children: _jsx(Card, { padding: 5, radius: 2, border: true, tone: tone, style: {
14
+ borderStyle: props.isOver ? undefined : 'dashed'
15
+ }, children: _jsxs(Stack, { space: 2, style: { textAlign: 'center' }, children: [_jsxs(Text, { size: 2, as: "h2", muted: true, children: [!props.isOver && props.title, isValid && 'Drop here', isInvalid && 'Invalid location or element'] }, void 0), props.subtitle && _jsx(Text, { size: 1, children: props.subtitle }, void 0), props.children] }, void 0) }, void 0) }, void 0));
16
16
  };
17
17
  export default PlaceholderDropzone;
@@ -32,9 +32,9 @@ const TreeEditor = (props) => {
32
32
  // Do nothing. onMoveNode will do all the work
33
33
  }, onVisibilityToggle: handleVisibilityToggle, onMoveNode: (data) => operations.handleMovedNode(data), treeData: localTree, ...getCommonTreeProps({
34
34
  placeholder: {
35
- title: 'Add items by dragging them here'
35
+ title: 'Add items from the list below'
36
36
  }
37
- }) }, void 0) }, void 0), allItemsStatus === 'success' && unaddedItems?.length > 0 && (_jsxs(Stack, { space: 1, paddingX: 2, paddingTop: 3, children: [_jsxs(Stack, { space: 2, paddingX: 2, paddingBottom: 3, children: [_jsx(Text, { size: 2, as: "h2", weight: "semibold", children: "Add more items" }, void 0), _jsx(Text, { size: 1, muted: true, children: "Only published documents are shown." }, void 0)] }, void 0), unaddedItems.map((item) => (_jsx(DocumentInNode, { item: item, action: _jsx(Tooltip, { placement: "left", content: _jsx(Box, { padding: 2, children: _jsx(Text, { size: 1, children: "Add to list" }, void 0) }, void 0), children: _jsx(Button, { onClick: () => {
37
+ }) }, void 0) }, void 0), allItemsStatus === 'success' && unaddedItems?.length > 0 && (_jsxs(Stack, { space: 1, paddingX: 2, paddingTop: 3, children: [_jsxs(Stack, { space: 2, paddingX: 2, paddingBottom: 3, children: [_jsx(Text, { size: 2, as: "h2", weight: "semibold", children: "Add more items" }, void 0), _jsx(Text, { size: 1, muted: true, children: "Only published documents are shown." }, void 0)] }, void 0), unaddedItems.map((item) => (_jsx(DocumentInNode, { item: item, action: _jsx(Tooltip, { portal: true, placement: "left", content: _jsx(Box, { padding: 2, children: _jsx(Text, { size: 1, children: "Add to list" }, void 0) }, void 0), children: _jsx(Button, { onClick: () => {
38
38
  operations.addItem(item);
39
39
  }, mode: "bleed", icon: AddCircleIcon, style: { cursor: 'pointer' } }, void 0) }, void 0) }, item.publishedId || item.draftId)))] }, void 0)), allItemsStatus === 'loading' && (_jsx(Flex, { padding: 4, align: 'center', justify: 'center', children: _jsx(Spinner, { size: 3, muted: true }, void 0) }, void 0)), allItemsStatus === 'error' && (_jsx(Flex, { padding: 4, align: 'center', justify: 'center', children: _jsx(Text, { size: 2, weight: "semibold", children: "Something went wrong when loading documents" }, void 0) }, void 0))] }, void 0) }, void 0) }, void 0));
40
40
  };
@@ -48,6 +48,7 @@ export default function createDeskHierarchy(props) {
48
48
  .child(Object.assign(mainList.serialize(), {
49
49
  type: 'component',
50
50
  component: deskTreeValidator(props),
51
- options: props
51
+ options: props,
52
+ __preserveInstance: true
52
53
  }, props.title ? { title: props.title } : {}));
53
54
  }
@@ -11,7 +11,7 @@ export default {
11
11
  name: 'tree',
12
12
  title: 'Tree',
13
13
  options: {
14
- referenceTo: ['document']
14
+ referenceTo: ['image']
15
15
  }
16
16
  })
17
17
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/hierarchical-document-list",
3
- "version": "0.1.0-next.2",
3
+ "version": "0.1.0-next.3",
4
4
  "author": "Sanity <hello@sanity.io>",
5
5
  "license": "MIT",
6
6
  "main": "lib/index.js",
package/screenshot-1.jpg CHANGED
Binary file
package/lib/types.d.ts DELETED
@@ -1,122 +0,0 @@
1
- import { SanityDocument } from '@sanity/client';
2
- import { ArraySchemaType } from '@sanity/types';
3
- import { NodeRendererProps, TreeItem } from 'react-sortable-tree';
4
- interface SanityReference {
5
- _type: 'reference';
6
- _ref: string;
7
- _weak?: boolean;
8
- }
9
- /**
10
- * Objects saved to tree documents in Sanity's Content Lake
11
- */
12
- export interface StoredTreeItem {
13
- _key: string;
14
- _type: 'hierarchy.node' | string;
15
- value?: {
16
- reference?: SanityReference;
17
- docType?: string;
18
- };
19
- /**
20
- * _key of parent node
21
- */
22
- parent?: string | null;
23
- }
24
- /**
25
- * Tree items enhanced locally in the client with info from `allItems` and `visibilityMap`.
26
- * `allItems` stop here and never become LocalTreeItems as they aren't added to react-sortable-tree.
27
- *
28
- * See `useLocalTree.ts` and `dataToEditorTree()`.
29
- */
30
- export interface EnhancedTreeItem extends StoredTreeItem {
31
- expanded?: boolean | undefined;
32
- /**
33
- * Used by DocumentInNode to render the preview for drafts if they exist.
34
- * Also informs document status icons.
35
- */
36
- draftId?: string;
37
- draftUpdatedAt?: string;
38
- /**
39
- * If not present, DocumentInNode will show up an error for invalid document.
40
- * - undefined `publishedId` could mean the document is either deleted, or it doesn't match GROQ filters anymore
41
- */
42
- publishedId?: string;
43
- publishedUpdatedAt?: string;
44
- }
45
- /**
46
- * Tree items as found in the sortable tree itself.
47
- */
48
- export declare type LocalTreeItem = EnhancedTreeItem & Pick<TreeItem, 'title' | 'children'>;
49
- export interface TreeInputOptions {
50
- /**
51
- * What document types this hierarchy can refer to.
52
- * Similar to the `to` property of the [reference field](https://www.sanity.io/docs/reference-type).
53
- */
54
- referenceTo: string[];
55
- /**
56
- * Used to provide fine-grained filtering for documents.
57
- */
58
- referenceOptions?: {
59
- /**
60
- * Static filter to apply to tree document queries.
61
- */
62
- filter?: string;
63
- /**
64
- * Parameters / variables to pass to the GROQ query ran to fetch documents.
65
- */
66
- filterParams?: Record<string, unknown>;
67
- };
68
- /**
69
- * How deep should editors be allowed to nest items.
70
- */
71
- maxDepth?: number;
72
- }
73
- export interface TreeFieldSchema extends Omit<ArraySchemaType, 'of' | 'type' | 'inputComponent' | 'jsonType'> {
74
- options: ArraySchemaType['options'] & TreeInputOptions;
75
- }
76
- export interface TreeDeskStructureProps extends TreeInputOptions {
77
- /**
78
- * _id of the document that will hold the tree data.
79
- */
80
- documentId: string;
81
- /**
82
- * (Optional)
83
- * Schema type for your hierarchical documents.
84
- * By default, the document will be of type `hierarchy.tree`, a type provided by the plugin.
85
- */
86
- documentType?: string;
87
- /**
88
- * (Optional)
89
- * Key for the field representing the hierarchical tree inside the document.
90
- * `tree` by default.
91
- */
92
- fieldKeyInDocument?: string;
93
- }
94
- export interface DocumentPair {
95
- draft?: SanityDocument;
96
- published?: SanityDocument;
97
- }
98
- export interface AllItems {
99
- [publishedId: string]: DocumentPair | undefined;
100
- }
101
- declare type DocumentOperation<Payload = unknown> = {
102
- execute?: (payload?: Payload) => void;
103
- disabled?: boolean | string;
104
- };
105
- export interface DocumentOperations {
106
- patch?: DocumentOperation<unknown[]>;
107
- commit?: DocumentOperation;
108
- del?: DocumentOperation;
109
- delete?: DocumentOperation;
110
- discardChanges?: DocumentOperation;
111
- duplicate?: DocumentOperation;
112
- restore?: DocumentOperation;
113
- unpublish?: DocumentOperation;
114
- publish?: DocumentOperation;
115
- }
116
- export interface VisibilityMap {
117
- [_key: string]: boolean;
118
- }
119
- export interface NodeProps extends NodeRendererProps {
120
- node: LocalTreeItem;
121
- }
122
- export {};
package/lib/types.js DELETED
@@ -1 +0,0 @@
1
- export {};