@obelism/content 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +112 -2
- package/dist/bin/content.js +216 -0
- package/dist/bridge.d.mts +82 -0
- package/dist/bridge.d.mts.map +1 -0
- package/dist/bridge.d.ts +82 -0
- package/dist/bridge.d.ts.map +1 -0
- package/dist/bridge.js +920 -0
- package/dist/bridge.mjs +915 -0
- package/dist/config-c6qktlz6.mjs +8 -0
- package/dist/config-ci2hxmas.js +13 -0
- package/dist/index.d.mts +93 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +93 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +300 -0
- package/dist/index.mjs +284 -0
- package/dist/preview-by8d54dt.js +68 -0
- package/dist/preview-kvotryzw.mjs +64 -0
- package/dist/prompt.d.mts +26 -0
- package/dist/prompt.d.mts.map +1 -0
- package/dist/prompt.d.ts +26 -0
- package/dist/prompt.d.ts.map +1 -0
- package/dist/prompt.js +112 -0
- package/dist/prompt.mjs +108 -0
- package/dist/site.d.mts +34 -0
- package/dist/site.d.mts.map +1 -0
- package/dist/site.d.ts +34 -0
- package/dist/site.d.ts.map +1 -0
- package/dist/site.js +310 -0
- package/dist/site.mjs +302 -0
- package/dist/types-pa96z6po.d.ts +120 -0
- package/dist/types-pa96z6po.d.ts.map +1 -0
- package/package.json +91 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Obelism
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,113 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Obelism Content JS SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
```bash
|
|
4
|
+
npm i @obelism/content
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
## ContentClient
|
|
8
|
+
|
|
9
|
+
Reads one space environment through the delivery API. The token decides the
|
|
10
|
+
space, the environment and whether drafts are visible: a delivery token
|
|
11
|
+
(`cms_d_…`) sees published content, a preview token (`cms_p_…`) drafts too.
|
|
12
|
+
Keep preview tokens server-side.
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { ContentClient } from '@obelism/content'
|
|
16
|
+
|
|
17
|
+
const content = new ContentClient({
|
|
18
|
+
token: process.env.CONTENT_DELIVERY_TOKEN,
|
|
19
|
+
// url: 'https://content.obelism.studio',
|
|
20
|
+
// locale: 'nl', depth: 1, richText: 'json', timeout: 10_000,
|
|
21
|
+
// init: { next: { revalidate: 60 } }, // passed to every fetch
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
await content.getPage('blog/hello') // Entry | null
|
|
25
|
+
await content.getEntry('entry_…') // Entry | null
|
|
26
|
+
await content.getEntries({ contentType: 'post', limit: 20, skip: 0 }) // { items, total, limit, skip }
|
|
27
|
+
for await (const post of content.getAllEntries({ contentType: 'post' })) {
|
|
28
|
+
}
|
|
29
|
+
await content.getContentModel() // the model file
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Each method takes `{ locale, depth, richText, init }` to override the
|
|
33
|
+
defaults. Missing pages and entries are `null`; any other failure throws a
|
|
34
|
+
`ContentApiError` with `status` and the API's `message`. Type your content
|
|
35
|
+
with generics: `content.getPage<Entry<{ title: string }>>('home')`.
|
|
36
|
+
|
|
37
|
+
## Preview
|
|
38
|
+
|
|
39
|
+
The visual editor loads your site with `?cms_preview=1&cms_entry=…&cms_environment=…`.
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { readPreviewParams } from '@obelism/content'
|
|
43
|
+
|
|
44
|
+
const client = readPreviewParams(request.url) ? previewClient : deliveryClient
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Visual editor bridge
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { getContentBridge } from '@obelism/content/bridge'
|
|
51
|
+
|
|
52
|
+
const bridge = getContentBridge()
|
|
53
|
+
bridge.on('update', ({ entry }) => render(entry)) // unsaved edits, as typed
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Mark blocks so editors can click them: `<section {...editable(block)}>`
|
|
57
|
+
(adds `data-cms-uid`). Without an `update` listener the page reloads after
|
|
58
|
+
each save. It replaces the `<script src=".../bridge.js">` tag; when a page has
|
|
59
|
+
both, it wraps the script's bridge instead of starting a second one. React
|
|
60
|
+
sites use `@obelism/content-react`.
|
|
61
|
+
|
|
62
|
+
## Prompt editing
|
|
63
|
+
|
|
64
|
+
Inside the visual editor, people who may edit get a prompt box at the bottom
|
|
65
|
+
of the page: they type what to change and it shows on the page right away,
|
|
66
|
+
unsaved, with undo. It acts on the selected block, or the whole entry. The
|
|
67
|
+
bridge adds it by default; it needs nothing from your site.
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
getContentBridge({ prompt: false }) // leave it out
|
|
71
|
+
getContentBridge({ prompt: { labels: { open: 'Bewerk met een prompt' } } })
|
|
72
|
+
|
|
73
|
+
// Your own UI instead:
|
|
74
|
+
const bridge = getContentBridge({ prompt: false })
|
|
75
|
+
bridge.on('change', ({ features, prompting, canUndo, selectedUid }) => …)
|
|
76
|
+
const { summary } = await bridge.prompt('Make the heading shorter')
|
|
77
|
+
bridge.undo()
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The CMS runs prompts on Workers AI. To use your own model, set a prompt
|
|
81
|
+
endpoint under Space settings → Prompt editing and answer it with
|
|
82
|
+
`createPromptHandler` (it verifies the signed request; you call the model):
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
// app/api/content-prompt/route.ts
|
|
86
|
+
import { createPromptHandler } from '@obelism/content/prompt'
|
|
87
|
+
|
|
88
|
+
export const POST = createPromptHandler({
|
|
89
|
+
secret: process.env.CONTENT_PROMPT_SECRET, // whsec_… from Space settings
|
|
90
|
+
generate: async ({ system, messages, schema }) => {
|
|
91
|
+
// call any model; return its JSON answer (object or text)
|
|
92
|
+
},
|
|
93
|
+
})
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Helpers
|
|
97
|
+
|
|
98
|
+
- `richTextToHtml(doc, { renderEntry?, renderAsset? })`, `richTextToPlainText(doc)`
|
|
99
|
+
- `imageUrl(asset, { w, h, fit, format, q })`, `imageSrcSet(asset, [480, 960])`
|
|
100
|
+
|
|
101
|
+
## CLI
|
|
102
|
+
|
|
103
|
+
Keeps a content model file in Git in step with an environment.
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
export CONTENT_MANAGEMENT_TOKEN=cms_m_…
|
|
107
|
+
npx @obelism/content model pull # write content/content-model.json
|
|
108
|
+
npx @obelism/content model plan # what applying would change
|
|
109
|
+
npx @obelism/content model apply # apply it, all or nothing
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Options: `--file`, `--url` (or `$CONTENT_URL`), `--prune`. In GitHub Actions
|
|
113
|
+
the plan is also written to the job summary.
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var node_util = require('node:util');
|
|
3
|
+
var config = require('../config-ci2hxmas.js');
|
|
4
|
+
var promises = require('node:fs/promises');
|
|
5
|
+
var node_path = require('node:path');
|
|
6
|
+
|
|
7
|
+
// Turns a model plan from the management API into text for a terminal, or
|
|
8
|
+
// Markdown for a GitHub step summary or pull request comment.
|
|
9
|
+
const ACTION_SIGN = {
|
|
10
|
+
create: '+',
|
|
11
|
+
update: '~',
|
|
12
|
+
delete: '-'
|
|
13
|
+
};
|
|
14
|
+
const FIELD_SIGN = {
|
|
15
|
+
added: '+',
|
|
16
|
+
removed: '-',
|
|
17
|
+
changed: '~'
|
|
18
|
+
};
|
|
19
|
+
const plural = (count, one, many)=>`${count} ${count === 1 ? one : many}`;
|
|
20
|
+
const describeChange = (change)=>{
|
|
21
|
+
const details = [];
|
|
22
|
+
for (const field of change.fields ?? []){
|
|
23
|
+
details.push(`${FIELD_SIGN[field.change] ?? '~'} field ${field.apiId}`);
|
|
24
|
+
}
|
|
25
|
+
if (change.reordered) details.push('fields reordered');
|
|
26
|
+
if (change.settingsChanged && change.action === 'update') {
|
|
27
|
+
details.push('name, kind or description');
|
|
28
|
+
}
|
|
29
|
+
if (change.affectedEntries && change.affectedEntries > 0) {
|
|
30
|
+
details.push(`removes values from ${plural(change.affectedEntries, 'entry', 'entries')}`);
|
|
31
|
+
}
|
|
32
|
+
return details;
|
|
33
|
+
};
|
|
34
|
+
const issueLine = ({ contentType, path, message })=>`${[
|
|
35
|
+
contentType,
|
|
36
|
+
path
|
|
37
|
+
].filter(Boolean).join(' › ')}: ${message}`;
|
|
38
|
+
// `applied` says whether the plan already happened.
|
|
39
|
+
const formatPlan = (plan, { markdown = false, applied = false } = {})=>{
|
|
40
|
+
const changes = plan.changes ?? [];
|
|
41
|
+
const issues = plan.issues ?? [];
|
|
42
|
+
const lines = [];
|
|
43
|
+
if (markdown) {
|
|
44
|
+
lines.push(applied ? '### Content model applied' : '### Content model plan', '');
|
|
45
|
+
}
|
|
46
|
+
if (issues.length > 0) {
|
|
47
|
+
const count = plural(issues.length, 'problem', 'problems');
|
|
48
|
+
lines.push(markdown ? `**${count} — nothing can be applied:**` : `${count}; nothing can be applied:`);
|
|
49
|
+
for (const issue of issues){
|
|
50
|
+
lines.push(`${markdown ? '- ' : ' '}${issueLine(issue)}`);
|
|
51
|
+
}
|
|
52
|
+
lines.push('');
|
|
53
|
+
}
|
|
54
|
+
if (changes.length === 0) {
|
|
55
|
+
lines.push(issues.length > 0 ? 'No other changes.' : 'No changes: the environment matches the file.');
|
|
56
|
+
} else {
|
|
57
|
+
lines.push(`${plural(changes.length, 'content type', 'content types')} ${applied ? 'changed' : 'to change'}:`);
|
|
58
|
+
if (markdown) lines.push('', '```diff');
|
|
59
|
+
for (const change of changes){
|
|
60
|
+
lines.push(`${ACTION_SIGN[change.action] ?? '~'} ${change.apiId} (${change.name})`);
|
|
61
|
+
for (const detail of describeChange(change))lines.push(` ${detail}`);
|
|
62
|
+
}
|
|
63
|
+
if (markdown) lines.push('```');
|
|
64
|
+
}
|
|
65
|
+
return lines.join('\n');
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// `content model pull | plan | apply`: keeps a content model file in a
|
|
69
|
+
// repository in step with an environment. The token comes from
|
|
70
|
+
// $CONTENT_MANAGEMENT_TOKEN, never from an argument, so it stays out of shell
|
|
71
|
+
// history and CI logs. In GitHub Actions the plan also goes to the job
|
|
72
|
+
// summary.
|
|
73
|
+
class CliError extends Error {
|
|
74
|
+
constructor(message, exitCode = 1){
|
|
75
|
+
super(message), this.exitCode = exitCode;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// Exit code: 0 done, 1 problems in the plan.
|
|
79
|
+
const runModelCommand = async ({ command, file, url, token, prune, log = console.log, summaryFile, fetch: fetchImpl = fetch })=>{
|
|
80
|
+
const call = async (method, path, body)=>{
|
|
81
|
+
const response = await fetchImpl(`${url}${config.MANAGEMENT_PATH}${path}`, {
|
|
82
|
+
method,
|
|
83
|
+
headers: {
|
|
84
|
+
Authorization: `Bearer ${token}`,
|
|
85
|
+
...body !== undefined && {
|
|
86
|
+
'Content-Type': 'application/json'
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
...body !== undefined && {
|
|
90
|
+
body: JSON.stringify(body)
|
|
91
|
+
}
|
|
92
|
+
}).catch((error)=>{
|
|
93
|
+
throw new CliError(`Could not reach ${url}: ${error.message}`);
|
|
94
|
+
});
|
|
95
|
+
const text = await response.text();
|
|
96
|
+
try {
|
|
97
|
+
return {
|
|
98
|
+
status: response.status,
|
|
99
|
+
ok: response.ok,
|
|
100
|
+
json: JSON.parse(text)
|
|
101
|
+
};
|
|
102
|
+
} catch {
|
|
103
|
+
throw new CliError(`${response.status} from ${url}: ${text.slice(0, 200)}`);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
if (command === 'pull') {
|
|
107
|
+
const { ok, json } = await call('GET', '/model');
|
|
108
|
+
if (!ok) throw new CliError(String(json.error ?? 'Pull failed'));
|
|
109
|
+
await promises.mkdir(node_path.dirname(file), {
|
|
110
|
+
recursive: true
|
|
111
|
+
});
|
|
112
|
+
await promises.writeFile(file, `${JSON.stringify(json, null, '\t')}\n`);
|
|
113
|
+
const count = Array.isArray(json.contentTypes) ? json.contentTypes.length : 0;
|
|
114
|
+
log(`Wrote ${count} ${count === 1 ? 'content type' : 'content types'} to ${file}.`);
|
|
115
|
+
return 0;
|
|
116
|
+
}
|
|
117
|
+
let text;
|
|
118
|
+
try {
|
|
119
|
+
text = await promises.readFile(file, 'utf8');
|
|
120
|
+
} catch {
|
|
121
|
+
throw new CliError(`Can't read ${file}. Run \`content model pull\` first?`);
|
|
122
|
+
}
|
|
123
|
+
let model;
|
|
124
|
+
try {
|
|
125
|
+
model = JSON.parse(text);
|
|
126
|
+
} catch (error) {
|
|
127
|
+
throw new CliError(`${file} is not valid JSON: ${error.message}`);
|
|
128
|
+
}
|
|
129
|
+
const { ok, status, json } = await call('POST', command === 'plan' ? '/model/plan' : '/model/apply', {
|
|
130
|
+
model,
|
|
131
|
+
prune
|
|
132
|
+
});
|
|
133
|
+
// A plan with issues, or an apply refused for them, still has the plan.
|
|
134
|
+
const plan = json.changes || json.issues ? json : null;
|
|
135
|
+
if (!plan) throw new CliError(String(json.error ?? `${command} failed (${status})`));
|
|
136
|
+
const applied = command === 'apply' && ok;
|
|
137
|
+
log(formatPlan(plan, {
|
|
138
|
+
applied
|
|
139
|
+
}));
|
|
140
|
+
if (summaryFile) {
|
|
141
|
+
await promises.appendFile(summaryFile, `${formatPlan(plan, {
|
|
142
|
+
markdown: true,
|
|
143
|
+
applied
|
|
144
|
+
})}\n`);
|
|
145
|
+
}
|
|
146
|
+
return !ok || (plan.issues?.length ?? 0) > 0 ? 1 : 0;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const USAGE = `Usage: content model <pull|plan|apply> [--file path] [--url origin] [--prune]
|
|
150
|
+
|
|
151
|
+
pull write the environment's model to the file
|
|
152
|
+
plan show what applying the file would change, and what stands in the way
|
|
153
|
+
apply apply the file in one transaction, or change nothing
|
|
154
|
+
|
|
155
|
+
--file the model file (default content/content-model.json)
|
|
156
|
+
--url the CMS (default $CONTENT_URL, else ${config.DEFAULT_URL})
|
|
157
|
+
--prune plan and apply also delete content types the file leaves out
|
|
158
|
+
|
|
159
|
+
Needs CONTENT_MANAGEMENT_TOKEN: a management token from Space settings.`;
|
|
160
|
+
const main = async ()=>{
|
|
161
|
+
let parsed;
|
|
162
|
+
try {
|
|
163
|
+
parsed = node_util.parseArgs({
|
|
164
|
+
allowPositionals: true,
|
|
165
|
+
options: {
|
|
166
|
+
file: {
|
|
167
|
+
type: 'string',
|
|
168
|
+
default: 'content/content-model.json'
|
|
169
|
+
},
|
|
170
|
+
url: {
|
|
171
|
+
type: 'string'
|
|
172
|
+
},
|
|
173
|
+
prune: {
|
|
174
|
+
type: 'boolean',
|
|
175
|
+
default: false
|
|
176
|
+
},
|
|
177
|
+
help: {
|
|
178
|
+
type: 'boolean',
|
|
179
|
+
short: 'h',
|
|
180
|
+
default: false
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
} catch (error) {
|
|
185
|
+
throw new CliError(`${error.message}\n\n${USAGE}`, 2);
|
|
186
|
+
}
|
|
187
|
+
const { values, positionals } = parsed;
|
|
188
|
+
const [group, command] = positionals;
|
|
189
|
+
if (values.help) {
|
|
190
|
+
console.log(USAGE);
|
|
191
|
+
return 0;
|
|
192
|
+
}
|
|
193
|
+
if (group !== 'model' || command !== 'pull' && command !== 'plan' && command !== 'apply') {
|
|
194
|
+
throw new CliError(USAGE, 2);
|
|
195
|
+
}
|
|
196
|
+
const token = process.env.CONTENT_MANAGEMENT_TOKEN;
|
|
197
|
+
if (!token) {
|
|
198
|
+
throw new CliError(`CONTENT_MANAGEMENT_TOKEN is not set.\n\n${USAGE}`, 2);
|
|
199
|
+
}
|
|
200
|
+
return runModelCommand({
|
|
201
|
+
command,
|
|
202
|
+
file: values.file,
|
|
203
|
+
url: config.normalizeUrl(values.url ?? process.env.CONTENT_URL ?? config.DEFAULT_URL),
|
|
204
|
+
token,
|
|
205
|
+
prune: values.prune,
|
|
206
|
+
summaryFile: process.env.GITHUB_STEP_SUMMARY || undefined
|
|
207
|
+
});
|
|
208
|
+
};
|
|
209
|
+
main().then((code)=>process.exit(code), (error)=>{
|
|
210
|
+
if (error instanceof CliError) {
|
|
211
|
+
console.error(error.message);
|
|
212
|
+
process.exit(error.exitCode);
|
|
213
|
+
}
|
|
214
|
+
console.error(error);
|
|
215
|
+
process.exit(1);
|
|
216
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Entry } from './index.mjs';
|
|
2
|
+
|
|
3
|
+
type BridgeEvents = {
|
|
4
|
+
update: {
|
|
5
|
+
entry: Entry;
|
|
6
|
+
selectedUid: string | null;
|
|
7
|
+
};
|
|
8
|
+
saved: Record<string, never>;
|
|
9
|
+
published: Record<string, never>;
|
|
10
|
+
change: BridgeState;
|
|
11
|
+
};
|
|
12
|
+
type BridgeEvent = keyof BridgeEvents;
|
|
13
|
+
type BridgeListener<E extends BridgeEvent> = (payload: BridgeEvents[E]) => void;
|
|
14
|
+
type BridgeState = {
|
|
15
|
+
features: readonly string[];
|
|
16
|
+
selectedUid: string | null;
|
|
17
|
+
prompting: boolean;
|
|
18
|
+
canUndo: boolean;
|
|
19
|
+
unsaved: boolean;
|
|
20
|
+
saving: boolean;
|
|
21
|
+
publishing: boolean;
|
|
22
|
+
selecting: boolean;
|
|
23
|
+
};
|
|
24
|
+
type PromptResult = {
|
|
25
|
+
summary: string;
|
|
26
|
+
};
|
|
27
|
+
type ContentBridge = {
|
|
28
|
+
readonly isEditing: boolean;
|
|
29
|
+
readonly mode: 'editor' | 'site' | null;
|
|
30
|
+
readonly entryId: string | null;
|
|
31
|
+
readonly environment: string | null;
|
|
32
|
+
on<E extends BridgeEvent>(event: E, listener: BridgeListener<E>): () => void;
|
|
33
|
+
getState(): BridgeState;
|
|
34
|
+
prompt(prompt: string, options?: {
|
|
35
|
+
uid?: string | null;
|
|
36
|
+
}): Promise<PromptResult>;
|
|
37
|
+
undo(): void;
|
|
38
|
+
save(): Promise<void>;
|
|
39
|
+
publish(): Promise<void>;
|
|
40
|
+
signOut(): void;
|
|
41
|
+
setSelecting(selecting: boolean): void;
|
|
42
|
+
select(uid: string | null): void;
|
|
43
|
+
destroy(): void;
|
|
44
|
+
};
|
|
45
|
+
declare const INITIAL_STATE: BridgeState;
|
|
46
|
+
|
|
47
|
+
type PromptLabels = {
|
|
48
|
+
open: string;
|
|
49
|
+
placeholder: string;
|
|
50
|
+
send: string;
|
|
51
|
+
undo: string;
|
|
52
|
+
close: string;
|
|
53
|
+
scopeEntry: string;
|
|
54
|
+
scopeBlock: string;
|
|
55
|
+
clearBlock: string;
|
|
56
|
+
working: string;
|
|
57
|
+
save: string;
|
|
58
|
+
publish: string;
|
|
59
|
+
saving: string;
|
|
60
|
+
publishing: string;
|
|
61
|
+
saved: string;
|
|
62
|
+
published: string;
|
|
63
|
+
unsaved: string;
|
|
64
|
+
signOut: string;
|
|
65
|
+
viewingDrafts: string;
|
|
66
|
+
selectHint: string;
|
|
67
|
+
};
|
|
68
|
+
declare const DEFAULT_PROMPT_LABELS: PromptLabels;
|
|
69
|
+
type PromptBoxOptions = {
|
|
70
|
+
labels?: Partial<PromptLabels> | undefined;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
type BridgeOptions = {
|
|
74
|
+
url?: string | undefined;
|
|
75
|
+
prompt?: boolean | PromptBoxOptions | undefined;
|
|
76
|
+
};
|
|
77
|
+
declare const peekContentBridge: () => ContentBridge | null;
|
|
78
|
+
declare const getContentBridge: ({ url, prompt, }?: BridgeOptions) => ContentBridge;
|
|
79
|
+
|
|
80
|
+
export { DEFAULT_PROMPT_LABELS, INITIAL_STATE, getContentBridge, peekContentBridge };
|
|
81
|
+
export type { BridgeEvent, BridgeEvents, BridgeListener, BridgeOptions, BridgeState, ContentBridge, PromptBoxOptions, PromptLabels, PromptResult };
|
|
82
|
+
//# sourceMappingURL=bridge.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.d.mts","sources":["../src/bridge/createBridge.ts","../src/bridge/promptBox.ts","../src/bridge.ts"],"mappings":";;AAIA,KAAK,YAAY;AACjB;AACA,eAAe,KAAK;AACpB;AACA;AACA,WAAW,MAAM;AACjB,eAAe,MAAM;AACrB,YAAY,WAAW;AACvB;AACA,KAAK,WAAW,SAAS,YAAY;AACrC,KAAK,cAAc,WAAW,WAAW,cAAc,YAAY;AACnE,KAAK,WAAW;AAChB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK,YAAY;AACjB;AACA;AACA,KAAK,aAAa;AAClB;AACA;AACA;AACA;AACA,iBAAiB,WAAW,sBAAsB,cAAc;AAChE,gBAAgB,WAAW;AAC3B;AACA;AACA,QAAQ,OAAO,CAAC,YAAY;AAC5B;AACA,YAAY,OAAO;AACnB,eAAe,OAAO;AACtB;AACA;AACA;AACA;AACA;AAEA,cAAc,aAAa,EAAE,WAAW;;AC9CxC,KAAK,YAAY;AACjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,cAAc,qBAAqB,EAAE,YAAY;AACjD,KAAK,gBAAgB;AACrB,aAAa,OAAO,CAAC,YAAY;AACjC;;ACnBA,KAAK,aAAa;AAClB;AACA,uBAAuB,gBAAgB;AACvC;AACA,cAAc,iBAAiB,QAAQ,aAAa;AACpD,cAAc,gBAAgB,sBAAsB,aAAa,KAAK,aAAa","names":[]}
|
package/dist/bridge.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Entry } from './index.js';
|
|
2
|
+
|
|
3
|
+
type BridgeEvents = {
|
|
4
|
+
update: {
|
|
5
|
+
entry: Entry;
|
|
6
|
+
selectedUid: string | null;
|
|
7
|
+
};
|
|
8
|
+
saved: Record<string, never>;
|
|
9
|
+
published: Record<string, never>;
|
|
10
|
+
change: BridgeState;
|
|
11
|
+
};
|
|
12
|
+
type BridgeEvent = keyof BridgeEvents;
|
|
13
|
+
type BridgeListener<E extends BridgeEvent> = (payload: BridgeEvents[E]) => void;
|
|
14
|
+
type BridgeState = {
|
|
15
|
+
features: readonly string[];
|
|
16
|
+
selectedUid: string | null;
|
|
17
|
+
prompting: boolean;
|
|
18
|
+
canUndo: boolean;
|
|
19
|
+
unsaved: boolean;
|
|
20
|
+
saving: boolean;
|
|
21
|
+
publishing: boolean;
|
|
22
|
+
selecting: boolean;
|
|
23
|
+
};
|
|
24
|
+
type PromptResult = {
|
|
25
|
+
summary: string;
|
|
26
|
+
};
|
|
27
|
+
type ContentBridge = {
|
|
28
|
+
readonly isEditing: boolean;
|
|
29
|
+
readonly mode: 'editor' | 'site' | null;
|
|
30
|
+
readonly entryId: string | null;
|
|
31
|
+
readonly environment: string | null;
|
|
32
|
+
on<E extends BridgeEvent>(event: E, listener: BridgeListener<E>): () => void;
|
|
33
|
+
getState(): BridgeState;
|
|
34
|
+
prompt(prompt: string, options?: {
|
|
35
|
+
uid?: string | null;
|
|
36
|
+
}): Promise<PromptResult>;
|
|
37
|
+
undo(): void;
|
|
38
|
+
save(): Promise<void>;
|
|
39
|
+
publish(): Promise<void>;
|
|
40
|
+
signOut(): void;
|
|
41
|
+
setSelecting(selecting: boolean): void;
|
|
42
|
+
select(uid: string | null): void;
|
|
43
|
+
destroy(): void;
|
|
44
|
+
};
|
|
45
|
+
declare const INITIAL_STATE: BridgeState;
|
|
46
|
+
|
|
47
|
+
type PromptLabels = {
|
|
48
|
+
open: string;
|
|
49
|
+
placeholder: string;
|
|
50
|
+
send: string;
|
|
51
|
+
undo: string;
|
|
52
|
+
close: string;
|
|
53
|
+
scopeEntry: string;
|
|
54
|
+
scopeBlock: string;
|
|
55
|
+
clearBlock: string;
|
|
56
|
+
working: string;
|
|
57
|
+
save: string;
|
|
58
|
+
publish: string;
|
|
59
|
+
saving: string;
|
|
60
|
+
publishing: string;
|
|
61
|
+
saved: string;
|
|
62
|
+
published: string;
|
|
63
|
+
unsaved: string;
|
|
64
|
+
signOut: string;
|
|
65
|
+
viewingDrafts: string;
|
|
66
|
+
selectHint: string;
|
|
67
|
+
};
|
|
68
|
+
declare const DEFAULT_PROMPT_LABELS: PromptLabels;
|
|
69
|
+
type PromptBoxOptions = {
|
|
70
|
+
labels?: Partial<PromptLabels> | undefined;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
type BridgeOptions = {
|
|
74
|
+
url?: string | undefined;
|
|
75
|
+
prompt?: boolean | PromptBoxOptions | undefined;
|
|
76
|
+
};
|
|
77
|
+
declare const peekContentBridge: () => ContentBridge | null;
|
|
78
|
+
declare const getContentBridge: ({ url, prompt, }?: BridgeOptions) => ContentBridge;
|
|
79
|
+
|
|
80
|
+
export { DEFAULT_PROMPT_LABELS, INITIAL_STATE, getContentBridge, peekContentBridge };
|
|
81
|
+
export type { BridgeEvent, BridgeEvents, BridgeListener, BridgeOptions, BridgeState, ContentBridge, PromptBoxOptions, PromptLabels, PromptResult };
|
|
82
|
+
//# sourceMappingURL=bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.d.ts","sources":["../src/bridge/createBridge.ts","../src/bridge/promptBox.ts","../src/bridge.ts"],"mappings":";;AAIA,KAAK,YAAY;AACjB;AACA,eAAe,KAAK;AACpB;AACA;AACA,WAAW,MAAM;AACjB,eAAe,MAAM;AACrB,YAAY,WAAW;AACvB;AACA,KAAK,WAAW,SAAS,YAAY;AACrC,KAAK,cAAc,WAAW,WAAW,cAAc,YAAY;AACnE,KAAK,WAAW;AAChB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK,YAAY;AACjB;AACA;AACA,KAAK,aAAa;AAClB;AACA;AACA;AACA;AACA,iBAAiB,WAAW,sBAAsB,cAAc;AAChE,gBAAgB,WAAW;AAC3B;AACA;AACA,QAAQ,OAAO,CAAC,YAAY;AAC5B;AACA,YAAY,OAAO;AACnB,eAAe,OAAO;AACtB;AACA;AACA;AACA;AACA;AAEA,cAAc,aAAa,EAAE,WAAW;;AC9CxC,KAAK,YAAY;AACjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,cAAc,qBAAqB,EAAE,YAAY;AACjD,KAAK,gBAAgB;AACrB,aAAa,OAAO,CAAC,YAAY;AACjC;;ACnBA,KAAK,aAAa;AAClB;AACA,uBAAuB,gBAAgB;AACvC;AACA,cAAc,iBAAiB,QAAQ,aAAa;AACpD,cAAc,gBAAgB,sBAAsB,aAAa,KAAK,aAAa","names":[]}
|