@tinacms/app 0.0.12 → 0.0.14

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.
@@ -1,205 +0,0 @@
1
- /**
2
- Copyright 2021 Forestry.io Holdings, Inc.
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
6
- http://www.apache.org/licenses/LICENSE-2.0
7
- Unless required by applicable law or agreed to in writing, software
8
- distributed under the License is distributed on an "AS IS" BASIS,
9
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
- See the License for the specific language governing permissions and
11
- limitations under the License.
12
- */
13
- import { DocumentBlueprint } from '../formify/types'
14
-
15
- type Location = number[] | null
16
-
17
- export const getBlueprintValues = (
18
- data: object,
19
- path: string,
20
- index: number = 0
21
- ): string[] | undefined => {
22
- if (!data) {
23
- return
24
- }
25
- const pathArray = path.split('.')
26
- const next = pathArray[index]
27
- if (next === '[]') {
28
- if (Array.isArray(data)) {
29
- const values: string[] = []
30
- data.forEach((item) => {
31
- const res = getBlueprintValues(item, path, index + 1)
32
- if (res) {
33
- res.forEach((item) => {
34
- values.push(item)
35
- })
36
- }
37
- })
38
- return values
39
- }
40
- } else {
41
- const value = data[next]
42
- // Is last item
43
- if (pathArray.length === index + 1) {
44
- if (Array.isArray(value)) {
45
- return value
46
- } else {
47
- return [value]
48
- }
49
- } else {
50
- return getBlueprintValues(value, path)
51
- }
52
- }
53
- }
54
-
55
- export const getAllIn = (
56
- data: object | object[] | null,
57
- path: string,
58
- index: number = 0,
59
- location: Location = null
60
- ): { value: { id: string }; location: Location }[] | undefined => {
61
- if (!data) {
62
- return
63
- }
64
- const pathArray = path.split('.')
65
- const next = pathArray[index]
66
- if (next === '[]') {
67
- if (Array.isArray(data)) {
68
- const values: { value: { id: string }; location: Location }[] = []
69
- data.forEach((item, dataIndex) => {
70
- const res = getAllIn(item, path, index + 1, [
71
- ...(location || []),
72
- dataIndex,
73
- ])
74
- if (res) {
75
- res.forEach((item) => {
76
- values.push(item)
77
- })
78
- }
79
- })
80
- return values
81
- }
82
- } else {
83
- const value = data[next]
84
- // Is last item
85
- if (pathArray.length === index + 1) {
86
- if (Array.isArray(value)) {
87
- const v = value.map((item, index) => ({
88
- value: item,
89
- location: [...(location || []), index],
90
- }))
91
- return v
92
- } else {
93
- if (typeof value === 'string') {
94
- const v = [{ value: { id: value }, location }]
95
- return v
96
- } else {
97
- // FIXME: this should always be `_internalSys.path` but we're not populating the
98
- // data properly on resolveData yet. But even when we are, will need to keep that out
99
- // of the user-provided payload (maybe not?)
100
- const id = value?._internalSys?.path || value?.id
101
- if (id) {
102
- const v = [{ value: { id, ...value }, location }]
103
- return v
104
- }
105
- }
106
- }
107
- } else {
108
- const v = getAllIn(value, path, index + 1, location)
109
- return v
110
- }
111
- }
112
- }
113
- export const getAllInBlueprint = (
114
- data: object | object[] | null,
115
- path: string,
116
- index: number = 0,
117
- location: Location = null
118
- ):
119
- | { value: { _internalSys: { path: string } }; location: Location }[]
120
- | undefined => {
121
- if (!data) {
122
- return
123
- }
124
- const pathArray = path.split('.')
125
- const next = pathArray[index]
126
- if (next === '[]') {
127
- if (Array.isArray(data)) {
128
- const values: {
129
- value: { _internalSys: { path: string } }
130
- location: Location
131
- }[] = []
132
- data.forEach((item, dataIndex) => {
133
- const res = getAllInBlueprint(item, path, index + 1, [
134
- ...(location || []),
135
- dataIndex,
136
- ])
137
- if (res) {
138
- res.forEach((item) => {
139
- values.push(item)
140
- })
141
- }
142
- })
143
- return values
144
- }
145
- } else {
146
- const value = data[next]
147
- // Is last item
148
- if (pathArray.length === index + 1) {
149
- if (Array.isArray(value)) {
150
- throw new Error(`Unexpected array value for getAllInBlueprint`)
151
- } else {
152
- if (typeof value === 'string') {
153
- throw new Error(`Unexpected string value for getAllInBlueprint`)
154
- } else {
155
- const id = value?._internalSys?.path || value?.id
156
- if (id) {
157
- const v = [
158
- { value: { _internalSys: value._internalSys }, location },
159
- ]
160
- return v
161
- }
162
- }
163
- }
164
- } else {
165
- const v = getAllInBlueprint(value, path, index + 1, location)
166
- return v
167
- }
168
- }
169
- }
170
-
171
- export const getBlueprintFromLocation = (
172
- location: string,
173
- blueprints: DocumentBlueprint[]
174
- ) => {
175
- const blueprintString = location
176
- .split('.')
177
- .map((item) => (isNaN(Number(item)) ? item : '[]'))
178
- .join('.')
179
- const blueprint = blueprints.find(({ id }) => id === blueprintString)
180
- if (!blueprint) {
181
- throw new Error(`Unable to find blueprint at ${blueprintString}`)
182
- }
183
- return blueprint
184
- }
185
-
186
- // FIXME: this assumes children are in order (which they
187
- // are AFAIK but shouldn't be relied on)
188
- export const getBlueprintChildren = (
189
- blueprint: DocumentBlueprint,
190
- blueprints: DocumentBlueprint[]
191
- ) => {
192
- const foundChildren: DocumentBlueprint[] = []
193
- blueprints.forEach((otherBlueprint) => {
194
- if (foundChildren.find(({ id }) => otherBlueprint.id.startsWith(id))) {
195
- return
196
- }
197
- if (
198
- otherBlueprint.id.startsWith(blueprint.id) &&
199
- otherBlueprint.id !== blueprint.id
200
- ) {
201
- foundChildren.push(otherBlueprint)
202
- }
203
- })
204
- return foundChildren
205
- }
@@ -1,52 +0,0 @@
1
- /**
2
- Copyright 2021 Forestry.io Holdings, Inc.
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
6
- http://www.apache.org/licenses/LICENSE-2.0
7
- Unless required by applicable law or agreed to in writing, software
8
- distributed under the License is distributed on an "AS IS" BASIS,
9
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
- See the License for the specific language governing permissions and
11
- limitations under the License.
12
- */
13
-
14
- import React from 'react'
15
- import TinaCMS, { TinaAdmin, useCMS } from 'tinacms'
16
- import { TinaEditProvider, useEditState } from 'tinacms/dist/edit-state'
17
- import { Preview } from './preview'
18
-
19
- // TODO: Resolve this to local file in tsconfig.json
20
- // @ts-expect-error
21
- import config from 'TINA_IMPORT'
22
-
23
- const SetPreview = ({ outputFolder }: { outputFolder: string }) => {
24
- const cms = useCMS()
25
- cms.flags.set('tina-preview', outputFolder)
26
- return null
27
- }
28
-
29
- export const TinaAdminWrapper = () => {
30
- return (
31
- // @ts-ignore JSX element type 'TinaCMS' does not have any construct or call signatures.ts(2604)
32
- <TinaCMS {...config} client={{ apiUrl: __API_URL__ }}>
33
- <SetPreview outputFolder={config.build.outputFolder} />
34
- <TinaAdmin preview={<Preview {...config} />} />
35
- </TinaCMS>
36
- )
37
- }
38
-
39
- const GoToEdit = () => {
40
- const { setEdit } = useEditState()
41
- setEdit(true)
42
- return <div>Going into edit mode</div>
43
- }
44
-
45
- function App() {
46
- return (
47
- <TinaEditProvider editMode={<TinaAdminWrapper />}>
48
- <GoToEdit />
49
- </TinaEditProvider>
50
- )
51
- }
52
- export default App
@@ -1,6 +0,0 @@
1
- <svg viewBox="0 0 66 80" fill="none" xmlns="http://www.w3.org/2000/svg">
2
- <title>Tina</title>
3
- <desc>A proud llama</desc>
4
- <path d="M39.4615 36.1782C42.763 33.4475 44.2259 17.3098 45.6551 11.5091C47.0843 5.70828 52.995 6.0025 52.995 6.0025C52.995 6.0025 51.4605 8.67299 52.0864 10.6658C52.7123 12.6587 57 14.4401 57 14.4401L56.0752 16.8781C56.0752 16.8781 54.1441 16.631 52.995 18.9297C51.8459 21.2283 53.7336 43.9882 53.7336 43.9882C53.7336 43.9882 46.8271 57.6106 46.8271 63.3621C46.8271 69.1136 49.5495 73.9338 49.5495 73.9338H45.7293C45.7293 73.9338 40.1252 67.2648 38.9759 63.9318C37.8266 60.5988 38.2861 57.2658 38.2861 57.2658C38.2861 57.2658 32.1946 56.921 26.7931 57.2658C21.3915 57.6106 17.7892 62.2539 17.1391 64.8512C16.4889 67.4486 16.2196 73.9338 16.2196 73.9338H13.1991C11.3606 68.2603 9.90043 66.2269 10.6925 63.3621C12.8866 55.4269 12.4557 50.9263 11.9476 48.9217C11.4396 46.9172 8 45.1676 8 45.1676C9.68492 41.7349 11.4048 40.0854 18.8029 39.9133C26.201 39.7413 36.1599 38.9088 39.4615 36.1782Z" fill="currentColor" />
5
- <path d="M20.25 63.03C20.25 63.03 21.0305 70.2533 25.1773 73.9342H28.7309C25.1773 69.9085 24.7897 59.415 24.7897 59.415C22.9822 60.0035 20.4799 62.1106 20.25 63.03Z" fill="currentColor" />
6
- </svg>
@@ -1,3 +0,0 @@
1
- @tailwind base;
2
- @tailwind components;
3
- @tailwind utilities;
@@ -1,24 +0,0 @@
1
- /**
2
- Copyright 2021 Forestry.io Holdings, Inc.
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
6
- http://www.apache.org/licenses/LICENSE-2.0
7
- Unless required by applicable law or agreed to in writing, software
8
- distributed under the License is distributed on an "AS IS" BASIS,
9
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
- See the License for the specific language governing permissions and
11
- limitations under the License.
12
- */
13
-
14
- import React from 'react'
15
- import ReactDOM from 'react-dom'
16
- import './index.css'
17
- import App from './App'
18
-
19
- ReactDOM.render(
20
- <React.StrictMode>
21
- <App />
22
- </React.StrictMode>,
23
- document.getElementById('root')
24
- )
@@ -1,150 +0,0 @@
1
- /**
2
- Copyright 2021 Forestry.io Holdings, Inc.
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
6
- http://www.apache.org/licenses/LICENSE-2.0
7
- Unless required by applicable law or agreed to in writing, software
8
- distributed under the License is distributed on an "AS IS" BASIS,
9
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
- See the License for the specific language governing permissions and
11
- limitations under the License.
12
- */
13
- import React from 'react'
14
- import { useMachine } from '@xstate/react'
15
- import { queryMachine, initialContext } from '../../lib/machines/query-machine'
16
- import { ChevronRightIcon, textFieldClasses, useCMS } from 'tinacms'
17
- import { ArrowRightIcon, ChevronLeftIcon } from '@heroicons/react/outline'
18
- import { useSearchParams } from 'react-router-dom'
19
-
20
- export const Preview = (props) => {
21
- const cms = useCMS()
22
- const [searchParams, setSearchParams] = useSearchParams()
23
- React.useEffect(() => {
24
- // We'll often land here with the preview route in the URL (eg. ?iframe-url=/posts)
25
- setSearchParams({})
26
- }, [])
27
- const machine = React.useMemo(
28
- () =>
29
- queryMachine.withContext({
30
- ...initialContext,
31
- url:
32
- searchParams.get('iframe-url') ||
33
- localStorage.getItem('tina-url') ||
34
- '/',
35
- cms,
36
- formifyCallback: props.formifyCallback,
37
- }),
38
- []
39
- )
40
-
41
- const [state, send] = useMachine(machine)
42
- const ref = React.useRef<HTMLIFrameElement>(null)
43
-
44
- React.useEffect(() => {
45
- if (ref.current) {
46
- send({ type: 'IFRAME_MOUNTED', value: ref.current })
47
- window.addEventListener('message', (event) => {
48
- console.log('parent: event received', event.data.type)
49
- if (event.data.type === 'open') {
50
- send({ type: 'ADD_QUERY', value: event.data })
51
- }
52
- if (event.data.type === 'close') {
53
- send({ type: 'REMOVE_QUERY', value: event.data.id })
54
- }
55
- })
56
- }
57
- }, [ref.current])
58
- React.useEffect(() => {
59
- setInterval(() => {
60
- if (ref.current) {
61
- const href = ref.current.contentWindow?.location.pathname
62
- if (href) {
63
- if (href === 'blank') return
64
-
65
- send({
66
- type: 'SET_DISPLAY_URL',
67
- value: href,
68
- })
69
- }
70
- }
71
- }, 300)
72
- }, [ref.current])
73
-
74
- return (
75
- <div className="h-full overflow-scroll">
76
- <div className="">
77
- <div className="col-span-5 ">
78
- <div className="h-screen flex flex-col">
79
- <div className="col-span-2 bg-gray-50 border-b border-gray-200">
80
- <div className="px-16 py-3 flex gap-3">
81
- <div className="relative flex-1">
82
- <form
83
- onSubmit={(e) => {
84
- e.preventDefault()
85
- send({ type: 'UPDATE_URL' })
86
- }}
87
- >
88
- <input
89
- type="text"
90
- style={{ borderRadius: '50px' }}
91
- className={`${textFieldClasses}`}
92
- onChange={(e) =>
93
- send({ type: 'SET_INPUT_URL', value: e.target.value })
94
- }
95
- value={
96
- state.context.inputURL !== null
97
- ? state.context.inputURL
98
- : state.context.displayURL || state.context.url
99
- }
100
- />
101
- <div className="absolute right-2 top-0 bottom-0 flex items-center">
102
- <button
103
- className={`relative inline-flex items-center px-2 py-2 rounded-full border text-sm font-medium focus:z-10 focus:outline-none focus:ring-1 ${
104
- state.context.inputURL
105
- ? 'border-blue-300 bg-blue-500 text-white hover:bg-blue-400'
106
- : 'border-gray-300 bg-white text-gray-500 hover:bg-gray-50'
107
- } focus:ring-blue-500 focus:border-blue-500`}
108
- >
109
- <span className="sr-only">Go</span>
110
- <ArrowRightIcon
111
- className="h-3 w-3"
112
- aria-hidden="true"
113
- />
114
- </button>
115
- </div>
116
- </form>
117
- </div>
118
- <span className="relative z-0 inline-flex shadow-sm rounded-md">
119
- <button
120
- type="button"
121
- onClick={() => history.back()}
122
- className="relative inline-flex items-center px-2 py-2 rounded-l-full border border-gray-200 bg-white text-sm font-medium text-gray-500 hover:bg-gray-50 focus:z-10 focus:outline-none focus:ring-1 focus:ring-blue-500 focus:border-blue-500"
123
- >
124
- <span className="sr-only">Previous</span>
125
- <ChevronLeftIcon className="h-5 w-5" aria-hidden="true" />
126
- </button>
127
- <button
128
- type="button"
129
- onClick={() => history.forward()}
130
- className="-ml-px relative inline-flex items-center px-2 py-2 rounded-r-full border border-gray-200 bg-white text-sm font-medium text-gray-500 hover:bg-gray-50 focus:z-10 focus:outline-none focus:ring-1 focus:ring-blue-500 focus:border-blue-500"
131
- >
132
- <span className="sr-only">Next</span>
133
- <ChevronRightIcon className="h-5 w-5" aria-hidden="true" />
134
- </button>
135
- </span>
136
- </div>
137
- </div>
138
- <div className="relative flex-1 bg-gray-300 col-span-2 overflow-scroll flex items-center justify-center">
139
- <iframe
140
- ref={ref}
141
- className="h-full w-full bg-white"
142
- src={state.context.url}
143
- />
144
- </div>
145
- </div>
146
- </div>
147
- </div>
148
- </div>
149
- )
150
- }
@@ -1,16 +0,0 @@
1
- /**
2
- Copyright 2021 Forestry.io Holdings, Inc.
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
6
- http://www.apache.org/licenses/LICENSE-2.0
7
- Unless required by applicable law or agreed to in writing, software
8
- distributed under the License is distributed on an "AS IS" BASIS,
9
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
- See the License for the specific language governing permissions and
11
- limitations under the License.
12
- */
13
-
14
- /// <reference types="vite/client" />
15
- /** This value is injected globally at build time */
16
- declare const __API_URL__: string
package/tsconfig.json DELETED
@@ -1,20 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ESNext",
4
- "useDefineForClassFields": true,
5
- "lib": ["DOM", "DOM.Iterable", "ESNext"],
6
- "allowJs": false,
7
- "skipLibCheck": true,
8
- "esModuleInterop": false,
9
- "allowSyntheticDefaultImports": true,
10
- "strict": true,
11
- "forceConsistentCasingInFileNames": true,
12
- "module": "ESNext",
13
- "moduleResolution": "Node",
14
- "resolveJsonModule": true,
15
- "isolatedModules": true,
16
- "noEmit": true,
17
- "jsx": "react-jsx"
18
- },
19
- "references": [{ "path": "./tsconfig.node.json" }]
20
- }
@@ -1,9 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "composite": true,
4
- "module": "ESNext",
5
- "moduleResolution": "Node",
6
- "allowSyntheticDefaultImports": true
7
- },
8
- "include": ["vite.config.ts"]
9
- }